R:cowplot

cowplot往往和ggplot一起连用,只不过cowplot没有灰色背景,比较好看,cowplot被CRAN所收录

install.packages("cowplot") #安装包
library(ggplot2)
require(cowplot)

theme_set(theme_cowplot(font_size=12))#去除网格线

ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + 
  geom_point(size = 2.5)
image.png

是不是很好看了

install.packages("cowplot") #安装包
library(ggplot2)
require(cowplot)

theme_set(theme_cowplot(font_size=12))#去除网格线

ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
  theme(axis.text.x = element_text(angle=70, vjust=0.5))
image.png

当然,利用cowplot也可以进行组合图形

library(ggplot2)
require(cowplot)

theme_set(theme_cowplot(font_size=12))#去除网格线

plot.mpg = ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + 
  geom_point(size = 2.5)

plot.diamonds = ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
  theme(axis.text.x = element_text(angle=70, vjust=0.5))


plot_grid(plot.mpg, plot.diamonds, labels = c("A", "B")) #每幅图按A,B进行标记
image.png

任意位置组合也是可以的

library(ggplot2)
require(cowplot)

theme_set(theme_cowplot(font_size=12))#去除网格线

plot.mpg = ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + 
  geom_point(size = 2.5)

plot.diamonds = ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
  theme(axis.text.x = element_text(angle=70, vjust=0.5))

plot_grid(plot.mpg, NULL, NULL, plot.diamonds, labels = c("A", "B", "C", "D"), ncol = 2) #图A

plot_grid(plot.mpg, plot.diamonds, labels = c("A", "B"), nrow = 2, align = "v") #图B,align是轴对齐的参数
图A
图B
library(ggplot2)
require(cowplot)

theme_set(theme_cowplot(font_size=12))#去除网格线

plot.mpg = ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + 
  geom_point(size = 2.5)

plot.diamonds = ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
  theme(axis.text.x = element_text(angle=70, vjust=0.5))

library(viridis)
ggdraw() +
  draw_plot(plot.diamonds + theme(legend.justification = "bottom"), 0, 0, 1, 1) +
  draw_plot(plot.mpg + scale_color_viridis(discrete = TRUE) + 
              theme(legend.justification = "top"), 0.5, 0.52, 0.5, 0.4) +
  draw_plot_label(c("A", "B"), c(0, 0.5), c(1, 0.92), size = 15)
字母图

参考:https://mp.weixin.qq.com/s?__biz=MzA5NjAyMzU1OA==&mid=2247484096&idx=1&sn=8a1c15a8720649dfb88a65cf9964255c&key=9d29629ef754d4874287f88a6c3ecfa188d3a0d9ba60add649ccc1aecd5421e4704f1a1ae6d2ef983211c9fd674663e5097c8d59dcb472edab654020f3b2b0f788055539c1e9e166ecce2f02e29aa2f0&ascene=1&uin=MjMyMjE5NDE0Mg%3D%3D&devicetype=Windows+10&version=62070158&lang=zh_CN&exportkey=A3fJarEkTDd11zsiU2z77K0%3D&pass_ticket=p5I30fUgsUQH1hYgfoGtZRzrt6tHH9YWq%2B4ZGgox4JQ49NUYMu%2BhWk4%2BD8%2BLkcFp

你可能感兴趣的:(R:cowplot)