其他
Y 叔出品:ggfun
Y 叔出品:ggfun
Y 叔 6 月 30 号在 R 官网上发了这个包,这个包可以给 ggplot 图例添加外框
、添加自定义图例
、改变字体
三个功能,来探索一下吧!
目录
ggfun
keybox gglegend set_font
1、安装 R 包
install.packages('ggfun')
2、使用示例
加载R包
library("grid")
library("ggplot2")
library(ggprism)
library(ggsci)
library("ggfun")
keybox:给图例添加边框:
data("mtcars")
p <- ggplot(mtcars,aes(x = mpg,y = disp)) +
geom_point(aes(color = factor(cyl)),size = 5) +
theme_prism() +
scale_color_aaas() +
theme(legend.position = c(0.8,0.8))
keybox(p, 'rect')
添加圆角虚线边框:
keybox(p, 'roundrect', gp = gpar(col = '#808080', lty = "dashed"))
gglegend:添加图例:
mtcars$cyl <- factor(mtcars$cyl)
p1 <- ggplot(mtcars,aes(x = cyl,y = disp)) +
geom_boxplot(width = 0.5,size = 1) +
geom_jitter(size = 6.5,width = 0.2,alpha = .5,show.legend = F) +
theme_prism() +
scale_color_aaas()
p1
p2 <- gglegend(aes(colour =VALUE, label=VALUE), data, geom_text, p1)
p2
library(patchwork)
p1 + p2
set_font:设置字体:
p2 <- ggplot(mtcars,aes(x = cyl,y = disp)) +
geom_boxplot(width = 0.5,size = 1) +
geom_jitter(aes(color = factor(cyl)),size = 6.5,width = 0.2,alpha = .5,show.legend = T) +
theme_prism() +
scale_color_aaas() +
theme(legend.position = c(0.1,0.9))
set_font(p2, family="Times", fontface="italic", color='firebrick')
欢迎小伙伴留言评论!
今天的分享就到这里了,敬请期待下一篇!
最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!
如果觉得对您帮助很大,打赏一下吧!