改文字字体、大小、斜体
- 字体family
- serif:Times New Roman
- sans:Arial
- mono:Couries New
- KT: 楷体
- ST:宋体
- 字体粗斜face
- "plain":不加粗
- "italic":斜体
- "bold":粗体
- "bold.italic":粗斜体
ggplot(mpg, aes(y = class)) +
geom_bar(aes(fill = drv),
position = position_stack(reverse = TRUE)) +
theme_classic()+
theme(
legend.position = c(0.89,0.2), ## 图例位置
legend.direction = "horizontal", ## 图例方向
axis.text.y=element_text(size=15, ## 字号大小
family = "mono", ## 字体
face="bold.italic"), ## 粗体,斜体
axis.text.x=element_text(size=15))
加文字注释
使用annotate函数
xrng=range(mpg$displ)
yrng=range(mpg$cty)
caption_df=data.frame(lab=c("The first line annotation",
"The second line annotation",
"The third line annotation"))
caption <- paste(caption_df$lab,
collapse = "n")
ggplot(mpg, aes(displ, cty)) +
geom_point() +
theme_classic()+
annotate(geom = "text",
x = xrng[2]*0.92,
y = yrng[2]*0.95,
label = caption)
(对喔,这个地方怎么让文字靠左对齐呢??还没有完善)
隐藏图例分组标题
使用guides(colour=guide_legend(title = NULL))
p1<-ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl),
shape = factor(cyl)))+
theme_bw()
p2<-ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl),
shape = factor(cyl)))+
theme_bw()+
guides(colour=guide_legend(title = NULL),
shape=guide_legend(title = NULL))
p1|p2
左边是不隐藏图例标题的,右边是隐藏了图例标题(这个例子举的不太好,看不出来4,6,8是什么,如果能明确看出来是什么分组的话,就可以不用分组group的标题了)
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!