2016-01-13 14 views
1

根據ggplot2的文檔,發現here,「panel.grid.minor」和「panel.grid.major」這兩個主題元素都從「panel.grid」繼承。ggplot2:「panel.grid.major」和「panel.grid.minor」從「panel.grid」繼承多少?

看來, 「panel.grid.major」,從 「panel.grid」 繼承了尺寸,而不是顏色:

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)) 

​​

enter image description here

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

enter image description here

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

enter image description here

次要網格線做既不繼承的尺寸,也沒有顏色。

我使用GGPLOT2的版本2.0.0:

> 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 
> 

有沒有「主題」的更詳細的文檔,或者是試錯的最好的人能做到?

+0

也許這可以幫助http://docs.ggplot2.org/dev/theme.html – MLavoie

回答

0

ggplot2::theme_grey(查看其源代碼)定義

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

您正在使用它作爲默認的主題。