Как переместить положение линий сетки? - PullRequest
0 голосов
/ 10 июля 2019

Я хочу, чтобы линии сетки моего гистограммы появлялись за решеткой.В настоящее время они появляются на верхней панели.Есть ли способ сделать это в базе R?

 initialmth <- structure(list( 
 A = c( 10, 4),
 B = c(28, 18),
 C = c(9, 1), 
 D = c(39, 33),
 E = c(13, 8),
 F = c(37, 27), 
 G = c(30, 51), 
 H = c(31, 41)),  


  .Names = c("Math has been my worst subject ",
         "I would consider a career that uses math ",
         "Math is hard for me",
         "I am the type of student to do well in math",
         "I cannot do a good job with math",
         "I could do advanced work in math",
         "I can get good grades in math",
         "I am good at math"
  ), 
   class = "data.frame", 
  row.names = c(NA, -2L)) #4L=number of numbers in each letter vector#

 attach(initialmth)
 print(initialmth)

  initialmth <- initialmth[, order(colSums(initialmth))]

 xFun <- function(x) x/2 + c(0, cumsum(x)[-length(x)])

par(mar=c(2, 17, 1, 2))
colors <- c("slategray3", "dodgerblue4")
byc <- barplot(as.matrix(initialmth), 
           beside = F, ylim = range(0, 15), xlim = range(0, 100),
           horiz = T, col=colors,  main="N=96", border=F, las=1, width 
           = 1.45, axes = 'n')

#adds % to scale
scale <- seq(0, 100, by = 20)
axis(side = 1, at = scale, labels = paste0(scale, "%"), cex.axis = 1)

#this adds gridlines
grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted",
 lwd = par("lwd"), equilogs = TRUE)

 # labels
 labs <- data.frame(x=as.vector(sapply(initialmth, xFun)),  # apply `xFun` 
  here 
               y=rep(byc, each=nrow(initialmth)),  # use `byc` here
               labels=as.vector(apply(initialmth, 1:2, paste0, "%")), 
               stringsAsFactors=FALSE)
   labs$labels[labs$labels %in% paste0(0:(8*100)/100, "%")] <- "" #masks 
   labels <8

 invisible(sapply(seq(nrow(labs)), function(x)  # `invisible` prevents 
 unneeded console output
 text(x=labs[x, 1:2], labels=labs[x, 3], cex=.9, font=2, col=0)))

Я бы хотел, чтобы линии сетки находились за решеткой на графике.В настоящее время они на вершине баров.В коде нет текущих сообщений об ошибках.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...