简体   繁体   English

oob=scales::squish 不适用于 ggplot2 中的 scale_size_continuous

[英]oob=scales::squish not working with scale_size_continuous in ggplot2

This is in relation to this question here: Adjust geom_point size so large values are plotted, but do not appear larger in ggplot2?这与这里的问题有关: 调整 geom_point 大小以便绘制大值,但在 ggplot2 中不会显得更大?

Specifically in reference to the response by @Axeman具体参考@Axeman 的回复

I couldn't comment on that question, and so had to ask a new question.我无法对这个问题发表评论,因此不得不提出一个新问题。

I wish to achieve the "squish"ing for the point size of geom_point , but the option oob=scales::squish doesn't work with scale_size_continuous .我希望为geom_point的点大小实现“挤压”,但选项oob=scales::squish squish 不适用于scale_size_continuous I am not sure what else am I missing.我不确定我还缺少什么。

Would appreciate any help.将不胜感激任何帮助。 Here is the code I tried:这是我尝试过的代码:

xx = ggplot(pcm, aes(x = variable, y = TF)) + 
  geom_point(aes(size = value, fill=value), shape = 21) + 
  scale_size_continuous(range=c(1, 12),
    limits = c(-2, 2),
    oob = scales::squish)

Further, I want to add that I cannot use scale_size_area as answered by @Axeman because I do not want 0 values to be mapped to points with size 0. The range of my data is approx.此外,我想补充一点,我不能使用scale_size_area回答的 scale_size_area 因为我不希望将 0 值映射到大小为 0 的点。我的数据范围约为。 from -1.7 to +3.从 -1.7 到 +3。 I want the smallest size allocated for the lowest negative value.我想要为最小的负值分配最小的大小。 Thanks.谢谢。

Is it a problem if you handle it with a transformation on value ?如果您通过value转换来处理它会不会有问题?

Here I just imagined how your data may look like:在这里,我只是想象您的数据可能是什么样子:

pcm <- data.frame(variable = runif(100),
                  TF       = runif(100),
                  value    = runif(100, -1.7, 3))

Here is the plot这是 plot

library(ggplot2)

ggplot(pcm, aes(x = variable, y = TF)) + 
    geom_point(aes(size = pmax(pmin(value, 2), -2), 
                   fill = value), 
               shape = 21) +
    labs(size = "value")

在此处输入图像描述

Let me know, I may be able to improve my answer.让我知道,我也许可以改进我的答案。

Also I would suggest you just a couple of updates to improve the readability of your chart, but it's up to you.此外,我建议您进行一些更新以提高图表的可读性,但这取决于您。

ggplot(pcm, aes(x = variable, y = TF)) + 
    geom_point(aes(size = pmax(pmin(value, 2), -2), 
                   colour = value), 
               alpha = 0.6) +
    labs(title = "Dots and colours",
         size = "value") +
    theme_minimal()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM