更改stat_sum中的垃圾箱以重叠点
我正在绘制每个站点上发现的样品计数。因此,样品越多,情节应该越大。计数范围从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 bins
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们可以通过
size
传奇调整scale_size_area()
函数,breaks breaks
参数:我已经对代码进行了一些调整:
删除
stat_sum
并将其放入geom_point()
审美:对于您的原始数据:
scale> scale_size_area(breaks = c(100,500,1000,1500,2000,2000,2000,2500) ) +
We could adapt the the
size
legend withscale_size_area()
function and thebreaks
argument:I have adapted the code a little:
Removed
stat_sum
and put it ingeom_point()
aesthetics:For your original data:
scale_size_area(breaks = c(100, 500, 1000, 1500, 2000, 2500)) +
@tarjae
谢谢您的回答。我还发现另一种方法是
我不需要scale_size_area
@TarJae
Thank you for your answer. I also figured out another way is
Then I do not need scale_size_area