- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为具有正值和负值的气泡图创建单个图例,如 plot below 中所示,使用 sp::bubble() 生成。
但是,出于各种原因,我想在 ggplot2 中复制它。我得到的最接近的是生成一个带有缩放符号的图例,但实际的气泡本身没有缩放。
上面的图是使用下面的代码创建的
# create data frame
x=sample(seq(1,50),50,T)
y=sample(seq(1,50),50,T)
plot_dat=data.frame(x=x,y=y,value=rnorm(50,0,25))
# plot
library(ggplot2)
ggplot(data=plot_dat, aes(x=x, y=y,colour=factor(sign(value)), size=value)) +
geom_point() +
scale_size(breaks = c(-40,-30,-20,-10,0,10,20,30,40,50), range = c(0.5,4)) +
scale_colour_manual(values = c("orange", "blue"), guide=F) +
guides(size = guide_legend(override.aes = list(colour = list("orange","orange","orange","orange","blue","blue","blue","blue","blue","blue"),size=c(3,2.5,2,1,0.5,1,2,2.5,3,4))))
最佳答案
继续对大小使用 abs(value),对颜色使用 sign(value)。
为 scale_size_continuous()
的 breaks=
参数提供所需中断的副本(例如 c(10,10,20,20,...))。接下来,为 labels=
提供您想要的值。最后,使用 guides()
和 override.aes
设置您自己的值和颜色顺序。
ggplot(data=plot_dat, aes(x=x, y=y,colour=factor(sign(value)), size=abs(value))) +
geom_point() +
scale_color_manual(values=c("orange","blue"),guide=FALSE)+
scale_size_continuous(breaks=c(10,10,20,20,30,30,40,40,50,50),labels=c(-50,-40,-30,-20,-10,10,20,30,40,50),range = c(1,5))+
guides(size = guide_legend(override.aes = list(colour = list("orange","orange","orange","orange","orange","blue","blue","blue","blue","blue"),
size=c(4.92,4.14,3.50,2.56,1.78,1.78,2.56,3.50,4.14,4.92))))
要为 guides()
函数中的 size=
参数分配精确值,您可以使用 中的函数
库。重新缩放您正在绘制的整个值范围,以及提供给 rescale()
>缩放scale_size_continuous()
中的 range=
参数的断点。
set.seed(1234)
x=sample(seq(1,50),50,T)
y=sample(seq(1,50),50,T)
plot_dat=data.frame(x=x,y=y,value=rnorm(50,0,20))
library(scales)
rescale(c(abs(plot_dat$value),10,20,30,40,50),to=c(1,5))[51:55]
[1] 1.775906 2.562657 3.349409 4.136161 4.922912
关于R,ggplot2 : creating a single legend in a bubble chart with positive and negative values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40703656/
好吧,虽然模式 [abc] 匹配单个字符 a、b 或 c 时,模式 [^abc] 匹配任何不是的给定字符 a、b 或c. 现在,如果我在上面的语句中用 string 替换 character,如果我还
我正在学习 Haskell atm,现在我找到了这个功能 const const (negate 1) (negate 2) 3 这个函数的结果是 -2 .我不明白为什么结果不是 -2。 const
我可以有 /[abcd]/、/(ab|cd)/ 和 /[^wxyz]/。为什么不是 /(^wx|yz)/ Apparently您可以通过简单地将功能与其他功能组合在一起来实现完全相同的效果,如下所示:
我正在尝试在我的 C++ 14 代码中执行一个简单的操作 pow(-0.89,-0.67),它给出了一个 NaN 作为结果。在 SciLab 中执行相同操作时,结果为 -1.08。在 C++ 中有什么
我又在与正则表达式作斗争了。我一直在尝试添加使用转义字符来转义自定义标记,例如 至 和 至 .在乔治的帮助下,here , 在尝试转义方法之前,以下表达式会产生所需的结果。 ('This is a
我使用三个值(=页数)A , B , C对于属性(property)is of type . 某些页面只有一个值 is of type ,某些页面具有所有三个值。 我想要#ask对于类型为 A 的页面
我正在尝试使用普罗米修斯数据源在 Grafana 中绘制条形图。 我的简单查询如下所示: max_over_time(energy_monitor_watthour_today[1d]) 我将 Gra
我正在尝试使用 if GNU 中的函数(与条件语句之一相反)make如果未定义特定变量,则为了将单词添加到列表中。我最终这样做的方法是将第二个参数留空,同时提供第三个参数,如下所示: FOO := b
以下程序应打印数组元素的总和是正数还是负数: #include #define ARR_SIZE 5 int main() { int array[ARR_SIZE] = {1,-2,3,4,
我试图在公式中替换所有缺少前面零的 float 。例如: “4+.5”应该变成:“4+0.5” 现在我读到 JavaScript 不支持向后看,那么我该如何实现呢?当前面有数字时,以下代码也会替换:
我有这个 64x64 二维数组 该阵列的数据可在此处下载 - http://m.uploadedit.com/ba3s/1494223164755.txt 现在,我想复制这个数组,其中具有最高值的区域
我在研究 String 及其构造函数时发现了一些我无法解释的行为。 我创建了以下方法 public static String negate(String s) { byte[] b = s.
我在我的应用程序的 Crashlytics 中看到了这次崩溃。我不知道哪里出了问题。 有人对为什么会发生这种崩溃有任何建议吗? Fatal Exception: java.lang.IllegalAr
我有一些异常值的数据集,例如以下 x <- rnorm(1000,0,20) x <- c(x, 500, -500) 如果我们以此绘制在线性x轴刻度上,我们将看到 histogram(x) 我想出了
tl;dr:我该如何做类似下面编写的代码的事情: def notFunctor[M[_] : Not[Functor]](m: M[_]) = s"$m is not a functor" 'Not[
我有一个程序可以替换文件中的内容。但是却导致了IO异常,我不知道我哪里逻辑错了? 代码如下: import java.io.File; import java.io.RandomAccessFile;
我正在验证整数是否为零或更大。将需求描述为“零或更大”感觉过于冗长。说“非负面”会引入负面语言,我会尽量避免。 在描述必须为零或更大的值时,您使用什么简洁的描述符? 最佳答案 positiveValu
我使用的是tinyMCE版本3,我使用的是富文本编辑器,它会在输入时计算剩余的字符数。由于 maxLength 属性不适用于tinyMCE3。我已经以这种方式进行了硬编码,但它也计算了空白字符
下面的示例在调用look_back_1()或look_back_2()时应该崩溃。原因:当对无符号变量求反时,结果应保持无符号。 #include int look_back_1(int *arr,
虽然我阅读了大量有关该主题的文章(特别是使用环视),但我不明白是否可以使用正则表达式解决这种更一般的情况。 设置: 1) 在 中传递了一个输入正则表达式2) 输入正则表达式嵌入到负正则表达式中,这样
我是一名优秀的程序员,十分优秀!