为什么 ggplot2 不允许我为每个单独的点设置大小?

发布于 2024-09-08 13:39:53 字数 515 浏览 0 评论 0原文

我有一个散点图。我想按每个点的频率来缩放其大小。所以我有一个相同长度的频率列。但是,如果我这样做:

... + 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以可爱出名 2024-09-15 13:39:53

您尝试过吗?

+ geom_point(aes(size = Freq))

使用 aes 函数将美学映射到数据中的变量。查看 http://had.co.nz/ggplot2/geom_point.html

Have you tried..

+ geom_point(aes(size = Freq))

Aesthetics are mapped to variables in the data with the aes function. Check out http://had.co.nz/ggplot2/geom_point.html

冷情 2024-09-15 13:39:53

好的,这可能就是您正在寻找的。您上面提供的代码将信息汇总为四类。如果您不想这样做,可以使用 scale_size_manual() 指定类别。

sizes <- unique(dcount$Freq)
names(sizes) <- as.character(unique(dcount$Freq))

ggplot(dcount,aes(x=Time,y=Counts)) + geom_point(aes(size=as.factor(Freq))) + scale_size_manual(values = sizes/2)

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().

sizes <- unique(dcount$Freq)
names(sizes) <- as.character(unique(dcount$Freq))

ggplot(dcount,aes(x=Time,y=Counts)) + geom_point(aes(size=as.factor(Freq))) + scale_size_manual(values = sizes/2)
小…红帽 2024-09-15 13:39:53

如果 gd047 给出的代码不起作用,我会仔细检查您的 Freq 列实际上称为 Freq 并且您的工作区没有其他名为 Freq 的对象代码>频率。除此之外,代码应该可以工作。你怎么知道尺度与频率无关?

If the code gd047 gave doesn't work, I'd double check that your Freq column is actually called Freq and that your workspace doesn't have some other object called Freq. Other than that, the code should work. How do you know that the scale has nothing to do with the frequency?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文