简体   繁体   中英

ggplot2: How much do “panel.grid.major” and “panel.grid.minor” inherit from “panel.grid”?

According to the documentation of ggplot2, found here , both theme elements "panel.grid.minor" and "panel.grid.major" inherit from "panel.grid".

It seems that "panel.grid.major" inherits the size from "panel.grid", but not the color:

library(ggplot2)

data <- data.frame( x = 1:12, y = 3*sin(1:12)-exp((1:12)/5) )

plt <- ggplot(data) +
  geom_line( aes(x=x,y=y), size=3, color="blue" ) +
  theme( panel.background = element_rect( fill="darkgrey" ),
         axis.text = element_text( size=18 ) )

.

> plt

在此处输入图片说明

> plt + theme( panel.grid = element_line( size=3, color="black" ) )

在此处输入图片说明

> plt + theme( panel.grid = element_line( size=3 ),
+              panel.grid.major = element_line( color="black" ) )

在此处输入图片说明

The minor grid lines do neither inherit the size, nor the color.

I'm using version 2.0.0 of ggplot2:

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plyr_1.8.3    igraph_1.0.1  ggplot2_2.0.0

loaded via a namespace (and not attached):
[1] labeling_0.3     colorspace_1.2-6 scales_0.3.0     magrittr_1.5    
[5] tools_3.2.3      gtable_0.1.2     Rcpp_0.12.2      grid_3.2.3      
[9] munsell_0.4.2   
> 

Is there a more detailed documentation of "theme", or is trial and error the best one can do?

ggplot2::theme_grey (see its source code) defines

panel.grid.major = element_line(colour = "white"), 
panel.grid.minor = element_line(colour = "white", size = 0.25), 

You are using it as the default theme.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM