【问题标题】:Combining three different plot created by geom_dotplot() in R?结合 R 中 geom_dotplot() 创建的三个不同的图?
【发布时间】:2019-10-21 11:33:18
【问题描述】:

我有三个不同的数据集代表不同年份的数据,它们都有相同的 y 轴和 x 轴?例如,如下图所示,除了它在 R 中并且是 dotplot

【问题讨论】:

  • aHI,请尽量让您的问题可重现。这包括示例代码(包括列出非基础 R 包)和示例明确数据(例如,dput(head(x))data.frame(x=...,y=...))。参考:stackoverflow.com/questions/5963269stackoverflow.com/help/mcvestackoverflow.com/tags/r/info。 (这里有两点:(1)通过不让我们不必要地创建数据,让我们可以轻松地帮助您;(2)表现出您的一些努力。)
  • ... 但总的来说,大多数(如果不是全部)ggplot2 geoms 允许“群体”美学(包括geom_dotplot,正如我在其他评论中所说),这将允许一些东西像这样。或者,您可以使用 facet_* 函数之一来生成数据方面,尽管这与您在此处演示的内容不完全一样。

标签: r graph dot


【解决方案1】:

组合图形以进行显示的一种方法是使用 ggplot 单独创建它们,然后将它们与拼凑而成。

library(ggplot2)
install.packages("devtools")
devtools::install_github("thomasp85/patchwork")
library(patchwork)


p1 <- ggplot(mtcars, aes(x = mpg)) + geom_dotplot()
p2 <- ggplot(mtcars, aes(x = hp)) + geom_dotplot()
p3 <- ggplot(mtcars, aes(x = wt)) + geom_dotplot()

p1 + p2 + p3

#or

ggplot(mtcars)  +
  geom_dotplot(aes(mpg)) +
  ggplot(mtcars) +
  geom_dotplot(aes(hp)) +
  ggplot(mtcars) +  
  geom_dotplot(aes(wt))

还有cowplot::plot_gridhttps://cran.r-project.org/web/packages/cowplot/vignettes/plot_grid.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多