【问题标题】:ggplot qplot (quick plot) with fill?ggplot qplot(快速绘图)填充?
【发布时间】:2020-04-17 12:51:37
【问题描述】:

如何使用填充快速绘制绘图(即qplot)?

我试过了

iris %>% qplot(Sepal.Length, fill = Species)
Error in FUN(X[[i]], ...) : object 'Sepal.Length' not found

iris %>% qplot(seq_along(Sepal.Length), Sepal.Length, fill = Species)
Error in FUN(X[[i]], ...) : object 'Sepal.Length' not found

但没有运气。

【问题讨论】:

  • qplot(Sepal.Length, fill = Species, data=iris)
  • @Edward 抱歉,我问了一个模棱两可的问题。我追求相当于qplot(seq_along(iris$Sepal.Length), iris$Sepal.Length),但以物种为填充。非常感谢您的帮助!
  • 没问题。你的问题总是具有挑战性。保持大脑工作。 ;)

标签: r ggplot2


【解决方案1】:

错误代码是因为%>%

管道不起作用,因为它默认将 lhs 作为 rhs 中的第一个参数,在 qplot 的情况下,这是x,而不是data。如果您仍想使用%>%,则需要指定要传递到哪个参数:

iris %>% qplot(data =., Sepal.Length, fill = Species)

并且,在您的第二个版本中,但有 @sahwahn 的更正

iris %>% qplot(data=., seq_along(Sepal.Length), Sepal.Length, color = Species)

【讨论】:

    【解决方案2】:

    如果您希望按物种绘制直方图和颜色,请将 Species 传递给 color 参数。

    qplot(data=iris, x=Sepal.Length, fill=Species)
    

    否则,如果您正在寻找绘图点:

    qplot(data=iris, x=seq_along(Sepal.Length), y=Sepal.Length, colour=Species)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-01
      • 2019-08-19
      • 2021-03-02
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多