rm(list = ls())
#加载R包
library(ggplot2)
#数据——以R自带示例数据iris为例
df<-iris
#绘制基本散点图
p<-ggplot(df) +
geom_point(aes(x = Sepal.Length, y = Sepal.Width,
alpha= Petal.Length ,
color = Species,
size = Petal.Width))
p1、theme_gray()
p1<-p+theme_gray()+ggtitle("theme_gray()")+
theme(legend.position = 'none')
p12、theme_bw()
p2<-p+theme_bw()+ggtitle("theme_bw()")+
theme(legend.position = 'none')
p23、theme_classic()
p3<-p+theme_classic()+ggtitle("theme_classic()")+
theme(legend.position = 'none')
p34、theme_light()
p4<-p+theme_light()+ggtitle("theme_light()")+
theme(legend.position = 'none')
p45、theme_void()
p5<-p+theme_void()+ggtitle("theme_void()")+
theme(legend.position = 'none')
p56、theme_linedraw()
p6<-p+theme_linedraw()+ggtitle("theme_linedraw()")+
theme(legend.position = 'none')
p67、theme_minimal()
p7<-p+theme_minimal()+ggtitle("theme_minimal()")+
theme(legend.position = 'none')
p78、theme_dark()
p8<-p+theme_dark()+ggtitle("theme_dark()")+
theme(legend.position = 'none')
p8cowplot::plot_grid(p1,p2,p3,p4,p5,p6,p7,p8,ncol = 4)#加载包
library(ggthemes)1、theme_clean()
p+theme_clean()2、theme_calc()
p+theme_calc()3、theme_economist()
p+theme_economist()4、theme_igray()
p+theme_igray()5、theme_fivethirtyeight()
p+theme_fivethirtyeight()6、theme_pander()
p+theme_pander()7、theme_foundation()
p+theme_foundation()8、theme_base()
p+theme_base()9、theme_par()
p+theme_par()10、theme_gdocs()
p+theme_gdocs()11、theme_map()
p+theme_map()12、theme_few()
p+theme_few()13、theme_tufte()
p+theme_tufte()14、theme_stata()
p+theme_stata()15、theme_excel()
p+theme_excel()16、theme_wsj()
p+theme_wsj()17、theme_hc()
p+theme_hc()18、theme_solid()
p+theme_solid()19、theme_solarized()
p+theme_solarized()ggprism包绘制GraphPad prism主题样式图形:
#加载包
library(ggprism)
names(ggprism_data$themes)
#44种主题样式名称,通过替换名称可实现更换主题风格目的示例:
p+theme_prism(palette = "autumn_leaves")p+theme_prism(palette = "pearl")p+theme_prism(palette = "summer")p+theme_prism(palette = "spring")p+theme_prism(palette = "ocean")#安装包
devtools::install_github('bbc/bbplot')
#加载包
library(bbplot)
#使用方式
p+bbc_style()具体细节可参见文章:https://www.jianshu.com/p/c1436793ad67
#安装包
devtools::install_github('Mikata-Project/ggthemr')
#加载包
library(ggthemr)使用方式:先通过ggthemr()函数设置主题,然后绘制图形即可:
1、flat
ggthemr("flat")
p2、flat dark
ggthemr("flat dark")
p3、solarized
ggthemr("solarized")
p4、camouflage
ggthemr('camouflage')
p5、chalk
ggthemr('chalk')
p6、copper
ggthemr('copper')
p7、dust
ggthemr('dust')
p8、earth
ggthemr('earth')
p9、fresh
ggthemr('fresh')
p10、grape
ggthemr('grape')
p11、grass
ggthemr('grass')
p12、greyscale
ggthemr('greyscale')
p13、light
ggthemr('light')
p14、lilac
ggthemr('lilac')
p15、pale
ggthemr('pale')
p16、sea
ggthemr('sea')
p17、sky
ggthemr('sky')
p通过theme()函数中不同参数自定义属于自己风格的主题,具体可参照此文章:https://www.jianshu.com/p/6cc0c17e30ce
base_theme <- theme(
plot.margin = unit(rep(1, 4), "cm"),
plot.title = element_text(size = 24, face = "bold",
color = "#22292F",
margin = margin(b = 8)),
plot.subtitle = element_text(size = 16,
lineheight = 1.1,
color = "#22292F",
margin = margin(b = 25)),
plot.caption = element_text(size = 12,
margin = margin(t = 25),
color = "#3D4852"),
axis.title.x = element_text(margin = margin(t = 15)),
axis.title.y = element_text(margin = margin(r = 15)),
axis.text = element_text(color = "#22292F")
)
#封装函数
set_base_theme <- function() {
theme_set(theme_minimal(base_size = 18) +
base_theme)
}
p+set_base_theme()#调用函数更多精彩欢迎大家关注微信公众号【科研后花园】!
| 留言与评论(共有 0 条评论) “” |