Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ggplot2-R中创建颜色的强度_R_Ggplot2 - Fatal编程技术网

在ggplot2-R中创建颜色的强度

在ggplot2-R中创建颜色的强度,r,ggplot2,R,Ggplot2,我希望颜色强度基于ggplot2/ggmap中变量的值。我使用了以下代码 print(ggmap(m) + geom_point(aes(x=longitude, y=latitude, size = variable2, colour = variable1) size = 3, pch = 20, data=combined1) +

我希望颜色强度基于ggplot2/ggmap中变量的值。我使用了以下代码

 print(ggmap(m) + 
                geom_point(aes(x=longitude, y=latitude, size = variable2, 
                               colour = variable1)
                               size = 3, pch = 20, data=combined1) + 
                scale_colour_continuous( low = "red", high = "green"))
但这里的问题是,有一些极值,比如80,70,而平均值在10-20左右。这不允许我正确地可视化整个图形,因为大多数图形都落在一个桶下。因此我在这里创建了一个bucket变量

combined1 = combined1 %>% mutate(bucket = ifelse(variable1 >= 0 & variable1< 5 ,'Less than 5',
                                        ifelse(variable1>= 5  & variable1< 10 ,'5-10',
                                               ifelse(variable1>= 10  & variable1< 15 ,'10-15',
                                                      ifelse(variable1>= 15  & variable1< 20 ,'15-20', 'Above 20')))))
这很有效,但它不像基于强度的图形。它是固定颜色的。所以我尝试了以下方法

 print(ggmap(m) + 
                geom_point(aes(x=longitude, y=latitude, size = variable2, 
                               colour = bucket)
                               size = 3, pch = 20, data=combined1) + 
                scale_colour_continuous( low = "red", high = "green"))
但是当我尝试这个的时候

Error: Discrete value supplied to continuous scale
我甚至尝试了
scale\u color\u discrete
,但还是出现了相同的错误。有谁能帮我得到水桶的强度图吗


谢谢

请尝试scale\u color\u brewer提供一些好的亮度色阶。并将cut()视为许多ifelse的替代方案statementes@RichardTelford我们怎样才能从粉红色变为深红色呢?它们是非常固定的调色板,对吗?比例\颜色\布鲁尔(调色板=“红色”)我确定了适合我需要的橙色调色板。但我这里有个小问题。它的顺序是10-15、15-20、5-10、20以上和5以下。有没有办法更改顺序?您有一个
因子
,默认情况下按字母顺序排列。您可以使用
reorder()
来更改基于值列的级别,或者在
factor()
中明确指定顺序,或者如果您按照建议使用
cut
,则它们的顺序已经正确。
Error: Discrete value supplied to continuous scale