【问题标题】:Histogram in R adding labels and colors to 2 hist plotsR中的直方图将标签和颜色添加到2个直方图
【发布时间】:2015-12-22 17:28:32
【问题描述】:

我有 2 个数据集,我在 R 中运行 hist 命令以创建直方图。最后,我将它们组合在一个情节中。所以我的代码是这样的:

hist(dist_x1,col="green",pch=20,cex=4,breaks=15)
hist(dist_x2,col="red",pch=20,cex=4,breaks=15,add=TRUE)
box()

我想在创建的直方图中放置 2 个标签(类似于 R 中的图例)来指示什么是什么,并区分这两个直方图存在于同一个图中。

有什么想法吗?

【问题讨论】:

  • 这个答案对你有用吗?
  • 是的,它工作得非常完美。我忘记了图例中的一个参数...我现在正在尝试使归一化曲线出现在历史图中...
  • 所以请标记正确:)

标签: r plot histogram


【解决方案1】:

您可以添加图例

dist_x1 <- rnorm(1000)
dist_x2 <- rnorm(500)
hist(dist_x1,col="green",pch=20,cex=4,breaks=15)
hist(dist_x2,col="red",pch=20,cex=4,breaks=15,add=TRUE)
legend("topright", c("dist_x1", "dist_x2"), fill=c("red", "green"))
box()

产量:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 2018-02-17
    • 2014-03-18
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多