Color management in horizontal lines in ggplot2

Can anyone tell me what is happening with this script? I need 2 horizontal, black, dashed lines, but instead I got two red continuations. I also canโ€™t change the color of the graph fields to black, despite the fact that you are using theme_bw, and the boxplot filling is not gray if required.

  dat1 <- data.frame (xvar = rep(c("A", "B"), each=10),

                yvar = 1:20 + rnorm(20,sd=3))

  ggplot(dat1, aes(x=xvar, y=yvar)) +
  theme_bw()+
  geom_boxplot(fill=grey)+
  geom_hline(aes(yintercept=40, color="black", linetype="dashed"))+
  geom_hline(aes(yintercept=33.84, color="black", linetype="dashed"))+  
  scale_x_discrete(name="") +
  scale_y_continuous(name="temperature (ยฐC)")+
  opts(
    panel.grid.major = theme_line(size = 0.5, colour = NA),
    panel.background = theme_rect(colour = NA),   
    axis.title.y = theme_text(angle=90,face="bold", colour="black", size=14),
    axis.text.y  = theme_text(face="bold",angle=0, size=14,colour="black"),
    axis.title.x = theme_text(face="bold", colour="black", size=14),
    axis.text.x  = theme_text( size=14,vjust=1.2, colour=NA))

Many thanks!

+5
source share
1 answer

As for the black dashed line, you should define it outside of aes (). Try using the code below:

geom_hline(aes(yintercept=40), color="black", linetype="dashed")

As for the window portion, you should fix your code below:

geom_boxplot(fill="gray")

, , , , , NA (..., panel.background = theme_rect (color = NA),...). , :

panel.background = theme_rect(colour = "black")

, .

+11

All Articles