2014-10-05 164 views
2

一旦有人将axis.text设置为element_blank(),可以轻松恢复原始设置。原来,我的意思是ggplot2的原件,而不是原来的那个时刻,element_blank()被设置。基本上,可以有像axis.text.x = element_default()ggplot2 - 将轴文本设置为element_blank后重置轴文本

library(ggplot2)  

# A while ago in my code, someone might do this 
x = ggplot(PlantGrowth, aes(x=group, y=weight)) + 
     geom_boxplot() + 
     theme(axis.text.x = element_blank()) 

# Is there an easy way for me to do this: 
x2 = x + theme(axis.text.x = default_ggplot2_value_for_this_item) 

回答

2

ggplot2的默认主题是theme_grey。这里有全部默认为:

line = element_line(colour = "black", size = 0.5, linetype = 1, lineend = "butt"), 
rect = element_rect(fill = "white", colour = "black", size = 0.5, linetype = 1), 
text = element_text(family = base_family, 
face = "plain", colour = "black", size = base_size, hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9), 
axis.text = element_text(size = rel(0.8), colour = "grey50"), 
strip.text = element_text(size = rel(0.8)), 
axis.line = element_blank(), 
axis.text.x = element_text(vjust = 1), 
axis.text.y = element_text(hjust = 1), 
axis.ticks = element_line(colour = "grey50"), 
axis.title.x = element_text(), 
axis.title.y = element_text(angle = 90), 
axis.ticks.length = unit(0.15, "cm"), 
axis.ticks.margin = unit(0.1, "cm"), 
legend.background = element_rect(colour = NA), 
legend.margin = unit(0.2, "cm"), 
legend.key = element_rect(fill = "grey95", colour = "white"), 
legend.key.size = unit(1.2, "lines"), 
legend.key.height = NULL, 
legend.key.width = NULL, 
legend.text = element_text(size = rel(0.8)), 
legend.text.align = NULL, 
legend.title = element_text(size = rel(0.8), face = "bold", hjust = 0),  
legend.title.align = NULL, 
legend.position = "right", 
legend.direction = NULL, 
legend.justification = "center", 
legend.box = NULL, 
panel.background = element_rect(fill = "grey90", colour = NA), 
panel.border = element_blank(), 
panel.grid.major = element_line(colour = "white"), 
panel.grid.minor = element_line(colour = "grey95", size = 0.25), 
panel.margin = unit(0.25, "lines"), 
panel.margin.x = NULL, 
panel.margin.y = NULL, 
strip.background = element_rect(fill = "grey80", colour = NA), 
strip.text.x = element_text(), 
strip.text.y = element_text(angle = -90), 
plot.background = element_rect(colour = "white"), 
plot.title = element_text(size = rel(1.2)), 
plot.margin = unit(c(1, 1, 0.5, 0.5), "lines"), complete = TRUE) 
+0

哇,这很完美。我猜你是从源头上复制的,你能否将我链接到我可以找到源代码的地方? – Hamy 2014-10-06 00:23:07

+2

只需在R控制台中键入'theme_grey'(无parens,no'?')。 – hrbrmstr 2014-10-06 00:43:59

+0

请注意,如果您实际尝试重置它,则必须重新指定'element_text'的所有参数,如下所示:'axis.text.x = element_text(family =“”,face =“plain”,color =“黑”,大小= 12,hjust = 0.5,vjust = 1,angle = 0,lineheight = 0.9)。 – 2017-04-07 16:35:17