p+theme_bw()+labs(subtitle="Change theme_bw") ggplot2 扩展包主题 代码语言:javascript 复制 library(ggthemes)p+theme_economist()+labs(subtitle="Change theme_economist")#其他可选#theme_economist theme_economist_white theme_wsj theme_excel theme_few #theme_foundation theme_igray theme_solarized th...
theme_grey()为默认主题,theme_bw()为白色背景主题,theme_classic()为经典主题。 p+theme_bw()+ labs(subtitle="Change theme_bw") ggplot2 扩展包主题 library(ggthemes) p + theme_economist() + labs(subtitle="Change theme_economist") #其他可选theme_economist theme_economist_whitetheme_wsjtheme_exc...
更改X轴和Y轴的颜色 使用:theme()函数即可 mytheme2<-theme_classic()+theme(text=element_text(family="sans",colour ="gray30",size = 12),axis.line=element_line(size=0.6,colour="gray30"),axis.ticks=element_line(size=0.6,colour="gray30"),axis.ticks.length=unit(1.5,units="mm"),plot.margi...
ggplot(data1, aes(v1, v2)) + geom_point() + theme_bw() # theme_bw()主题。 ggplot(data1, aes(v1, v2)) + geom_point() + theme_linedraw() # theme_linedraw() ggplot(data1, aes(v1, v2)) + geom_point() + theme_light() # theme_light() ggplot(data1, aes(v1, v2)) ...
输入?theme可以看到theme()功能的大量参数,可以实现与外观相关的大多数要求。其中有四种主要类型: element_text():使用element_text()函数设置基于文本的组件,如title,subtitle 和caption等。 element_line():使用element_line()设置基于线的组件,如轴线,主网格线和次网格线等。
theme是解决图是否美观的一个工具,其与scale最大的区别在于不受数据左右。先把scale做好,就是一张合格的图;再处理theme,则是一张出色的图。 载入数据,R包 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 library(ggplot2)#载入数据data(diamonds)set.seed(1234)diamond<-diamonds[sample(nrow(diam...
theme_gray(): gray background color and white grid lines theme_bw() : white background and gray grid lines p+theme_gray(base_size = 14) 1. p+theme_bw() 1. theme_linedraw : black lines around the plot theme_light : light gray lines and axis (more attention towards the data) p ...
除此外,ggplot2提供一些已经写好的主题,比如theme_grey()为默认主题,theme_bw()为白色背景主题,theme_classic()为经典主题。 p + theme_classic() 1. 3 ggplot2 扩展包主题 library(ggthemes) p + theme_stata() 1. 2. 除上述外,ggthemes包还提供其他主题,小伙伴们自己尝试吧。
除了scale_*_*()函数族,另一个对图形细节更重要的函数就是theme()函数,它可以让我们近乎随心所欲地修改我们图片的外观细节,其实我们在上一讲中用到的theme_bw()函数就是ggplot2为我们整合的theme()函数之一,我们可以直接使用以获得更好的视觉效果,但如果我们想要自己自定义图形的外观,我们就需要了解theme()函数...
这很容易,把ggplot2默认主题的设置函数theme_bw()的代码拿出来看看就知道了: library(ggplot2) theme_gray# 函数名不加括号,获得函数的代码 ## function (base_size = 12, base_family = "") ## { ## theme(line = element_line(colour = "black", size = 0.5, linetype = 1, ## lineend = "...