小提琴图

载入R包。


library(ggplot2)


用R自带数据集iris中的两个变量 (Species和Sepal.Length),画出一个小提琴图。


ggplot(iris, aes(x = Species, y = Sepal.Length)) + 
  geom_violin()


简单修饰。


ggplot(iris1, aes(x = Species, y = Sepal.Length, colour = Species)) + 
  geom_violin(size = 1, trim = FALSE) +
  scale_colour_manual(values = c("steelblue", "orange", "firebrick")) +
  theme_bw() +
  theme(legend.position = "none")


▌欢迎关注公众号:R语言和统计
▌课程相关咨询可添加R师妹微信: kefu_rstats
▌邮箱:contact@rstats.cn
▌网站:www.rstats.cn
我们致力于让R语言和统计变得简单!



2023-02-22 16:10
首页    ggplot2    小提琴图