更改stat_sum中的垃圾箱以重叠点

发布于 2025-02-05 01:15:48 字数 1324 浏览 3 评论 0原文

我正在绘制每个站点上发现的样品计数。因此,样品越多,情节应该越大。计数范围从1到2500。默认情况下,传说自动决定将数据显示并将数据集成到我想在下端扩展的范围。它从500开始,但我希望看到它从100开始,但仍然没有那么多,以至于我有10个以上的bins “在此处输入图像说明”

我试图理解scale_size_binned命令,因为我有这种感觉这是它可以正常工作的地方,但是当我尝试设置限制或范围时,它会使传奇项目显示越来越大的计数,但没有数字。因此,在没有值的500个上方将有一个较小的圆,而较大的圆圈低于2500,没有值。它还在值之间的传说中添加了刻度标记。实际上,除了4个值外,所有值实际上均为 500,因此我甚至不确定为什么比例默认为500。范围为12-2683平均值为339。 这是我的一些数据:

A tibble: 33 x 3
# Groups:   Site [20]
   Site    Sample       n
   <fct>  <chr> <int>
 1 1(20A) 20A     279
 2 1(20C) 20C      99
 3 2(20C) 20C     158
 4 3(25C) 25C     170
 5 4(25C) 25C     117
 6 5(20B) 20B      72
 7 6(20F) 20F     369
 8 7(19D) 19D     218
 9 8(20E) 20E    1044
10 9(20F) 20F     427

这是使用的代码

nb.cols = 20  
mycolors <- colorRampPalette(brewer.pal(12, "Paired"))(nb.cols) #tryin to find a palette with 33 colors

ggplot(data, aes(x = Sample, y = Site)) +
          stat_sum(aes(size = n, color= Site)) +
          scale_color_manual(values = mycolors)+
          guides(color = "none")+
         labs(x = "Sample", y = "Site", size = "Found")+
         theme_classic(base_size=14, base_family='serif')

I am plotting the count of samples found at each site. So the more samples, the bigger the plot point should be. The counts range from 1 to 2500. By default the legend automatically decides to display and bin the data into a range that I would like to expand on the lower end. It starts at 500, but I would like to see it start at 100, but still not get so excessive that I have more than 10 binsenter image description here

I have tried to understand the scale_size_binned command as I kind of feel this is where it would work, but when I try to set the limits or the range, it makes a legend item show for a smaller and larger count but with no numbers. So, there would be a smaller circle above the 500 with no value and a larger circle below 2500 with no value. It also puts in tick marks in the legend between values. In reality, all but 4 values are actually under 500 so Im not even sure why the scale starts at 500 by default. The range is 12-2683 mean is 339.
Here is some of my data:

A tibble: 33 x 3
# Groups:   Site [20]
   Site    Sample       n
   <fct>  <chr> <int>
 1 1(20A) 20A     279
 2 1(20C) 20C      99
 3 2(20C) 20C     158
 4 3(25C) 25C     170
 5 4(25C) 25C     117
 6 5(20B) 20B      72
 7 6(20F) 20F     369
 8 7(19D) 19D     218
 9 8(20E) 20E    1044
10 9(20F) 20F     427

Here is the code Ive used

nb.cols = 20  
mycolors <- colorRampPalette(brewer.pal(12, "Paired"))(nb.cols) #tryin to find a palette with 33 colors

ggplot(data, aes(x = Sample, y = Site)) +
          stat_sum(aes(size = n, color= Site)) +
          scale_color_manual(values = mycolors)+
          guides(color = "none")+
         labs(x = "Sample", y = "Site", size = "Found")+
         theme_classic(base_size=14, base_family='serif')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

表情可笑 2025-02-12 01:15:48

我们可以通过size传奇调整scale_size_area()函数,breaks breaks参数:

我已经对代码进行了一些调整:
删除stat_sum并将其放入geom_point()审美:

对于您的原始数据:scale> scale_size_area(breaks = c(100,500,1000,1500,2000,2000,2000,2500) ) +

library(tidyverse)

ggplot(df, aes(x = Sample, y = Site)) +
  geom_point(aes(color = factor(n), size = n)) +
  scale_size_area(breaks = seq(100,1000,100)) +
  scale_color_manual(values = mycolors) +
  guides(color = "none")+
  labs(x = "Sample", y = "Site", size = "Found")+
  theme_classic(base_size=14, base_family='serif')

”在此处输入图像说明”

We could adapt the the size legend with scale_size_area() function and the breaks argument:

I have adapted the code a little:
Removed stat_sum and put it in geom_point() aesthetics:

For your original data: scale_size_area(breaks = c(100, 500, 1000, 1500, 2000, 2500)) +

library(tidyverse)

ggplot(df, aes(x = Sample, y = Site)) +
  geom_point(aes(color = factor(n), size = n)) +
  scale_size_area(breaks = seq(100,1000,100)) +
  scale_color_manual(values = mycolors) +
  guides(color = "none")+
  labs(x = "Sample", y = "Site", size = "Found")+
  theme_classic(base_size=14, base_family='serif')

enter image description here

债姬 2025-02-12 01:15:48

@tarjae
谢谢您的回答。我还发现另一种方法是

    scale_size_continuous(breaks = c(25, 50, 100, 500,1000,2500), 
                                   labels = c(25,50, 100, 500, 1000,2500))+

我不需要scale_size_area

@TarJae
Thank you for your answer. I also figured out another way is

    scale_size_continuous(breaks = c(25, 50, 100, 500,1000,2500), 
                                   labels = c(25,50, 100, 500, 1000,2500))+

Then I do not need scale_size_area

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