为什么 ggplot2 不允许我为每个单独的点设置大小?
我有一个散点图。我想按每个点的频率来缩放其大小。所以我有一个相同长度的频率列。但是,如果我这样做:
... + geom_point(size=Freq)
我会收到此错误:
When _setting_ aesthetics, they may only take one value. Problems: size
我将其解释为所有点只能有 1 个大小。那么我该如何做我想做的事呢?
更新:数据位于此处 我使用的基本代码是:
dcount=read.csv(file="New_data.csv",header=T)
ggplot(dcount,aes(x=Time,y=Counts)) + geom_point(aes(size=Freq))
I've got a scatter plot. I'd like to scale the size of each point by its frequency. So I've got a frequency column of the same length. However, if I do:
... + geom_point(size=Freq)
I get this error:
When _setting_ aesthetics, they may only take one value. Problems: size
which I interpret as all points can only have 1 size. So how would I do what I want?
Update: data is here
The basic code I used is:
dcount=read.csv(file="New_data.csv",header=T)
ggplot(dcount,aes(x=Time,y=Counts)) + geom_point(aes(size=Freq))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尝试过吗?
使用
aes
函数将美学映射
到数据中的变量。查看 http://had.co.nz/ggplot2/geom_point.htmlHave you tried..
Aesthetics are
mapped
to variables in the data with theaes
function. Check out http://had.co.nz/ggplot2/geom_point.html好的,这可能就是您正在寻找的。您上面提供的代码将信息汇总为四类。如果您不想这样做,可以使用
scale_size_manual()
指定类别。ok, this might be what you're looking for. The code you provided above aggregates the information into four categories. If you don't want that, you can specify the categories with
scale_size_manual()
.如果 gd047 给出的代码不起作用,我会仔细检查您的
Freq
列实际上称为Freq
并且您的工作区没有其他名为Freq
的对象代码>频率。除此之外,代码应该可以工作。你怎么知道尺度与频率无关?If the code gd047 gave doesn't work, I'd double check that your
Freq
column is actually calledFreq
and that your workspace doesn't have some other object calledFreq
. Other than that, the code should work. How do you know that the scale has nothing to do with the frequency?