【发布时间】:2012-10-05 10:55:50
【问题描述】:
我想从一个数据框中绘制(直方图)每个长度类的鱼数,该数据框以分箱格式(data.frame(...,length=length,counts=N))总结了这些信息。我是 ggplot2 的新用户,但似乎它可能是一个不错的选择。我可以从 data.frame 对象创建这个直方图吗?
抱歉这么简短,这里是一段df的结构,
'data.frame': 416 obs. of 3 variables:
$ specie: Factor w/ 1 level "speciesA": 1 1 1 1 1 1 1 1 1 1 ...
$ length: num 34.5 35 35.5 36 36.5 37 37.5 38 38.5 39 ...
$ Counts: num 2 0 0 0 1 0 1 1 0 1 ...
在这种情况下,渔民捕获 2 个 34.5 厘米大的个体,1 个 36.5 厘米,依此类推... 非常感谢您的回答
【问题讨论】:
-
能否提供几行数据?
-
欢迎来到 SO,如果您给我们一个 reproducible example 和使用
dput(your.data)的数据样本,您的问题会更好地理解 -
试试这个,但是我不能给你一个合理的解决方案,而不会从你这边对你的数据结构有任何提示。设置 xmin 和 xmax 的值。查看 ggplot2 包的帮助页面:?geom_histogram
-
require("ggplot2"); ggplot(data=data, aes(x=
Fishes per length, xmin=, xmax=)) + stat_bin(binwidth = 1)
标签: r ggplot2 dataframe histogram