【问题标题】:How to build Plot Histogram in R with multiple variables?如何在 R 中构建具有多个变量的绘图直方图?
【发布时间】:2020-08-10 11:38:30
【问题描述】:

有人帮我建立这个数据集的直方图吗?

dat2 <- data.frame(mean_setosa, mean_versicolor, mean_virginica)

谢谢!

enter image description here

【问题讨论】:

    标签: r plot histogram


    【解决方案1】:

    你可以使用barplot:

    d <- aggregate(Petal.Length~Species, data = iris, FUN = mean)
    
         Species Petal.Length
    1     setosa        1.462
    2 versicolor        4.260
    3  virginica        5.552
    
    
    barplot(Petal.Length~Species, data = d)
    

    使用ggplot2 图形包,您可以:

    library(ggplot2)
    
    ggplot(d, aes(x = Species, y = Petal.Length))+
      geom_col()
    

    【讨论】:

    • 谢谢你的回答,我按照你的建议做了同样的事情,但是有一个错误Error in barplot.default(Species ~ Petal.Length, data = d) : 'height' must be a vector or a matrix
    • 你颠倒了SpeciesPetal.Length。请仔细检查您是否按原样复制了我提供的代码。
    • 我知道了,非常感谢!
    猜你喜欢
    • 2018-05-07
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 2019-12-16
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多