发散尺寸比例尺ggplot2 [英] diverging size scale ggplot2

查看:148
本文介绍了发散尺寸比例尺ggplot2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在空间位置映射模型/观测差异。我有颜色映射到差异,但我也想映射大小差异。我目前将尺寸映射到abs(差异),但它产生了两个不同的传说,我想合并。将大小映射到差异会为负值创建小点,为正值创建大点,但我真的只希望为过度/欠量预测显示幅度。如果它有所作为,我还希望尺度是离散的。
谢谢

一些测试数据:

  so。 df = data.frame(lat = runif(50,33,43),long = runif(50,-112,-104),diff = runif(50,-2,2))
ggplot()+
geom_point(data = so.df,aes(x = long,y = lat,color = diff,size = abs(diff)),alpha = 0.8)+
scale_color_gradient2(low ='red' ,mid ='white',high ='blue',limits = c(-0.6,0.6),breaks = c(-0.6,-0.4,-0.2,-0.1,0,0.1,0.2,0.6))+
guides(color = guide_legend('SWE Differences(m)'),size = guide_legend('SWE Difference \Magnitudes(m)'))+
coord_cartesian(xlim = c(-112.5,-104.25 ),ylim = c(33,44))+
theme_bw()

编辑:
使用离散色标我使用以下内容(对建议开放)

  so.df $ cut = cut_interval(so.df $ diff,length = 0.15)
ggplot()+
geom_path(data = states,aes(x = long,y = lat,group = group),color ='grey10 ')+
geom_point(data = so.df,aes(x = long,y = lat,color = cuts,size = abs(diff)),alpha = 0.8)+
coord_cartesian(xlim = c(-112.5,-104.25),ylim = c(33,44))+
scale_colour_brewer(type ='div',palette ='RdYlBu')+
guides(color = guide_legend('SWE Differences(m)'),size = guide_legend('SWE Difference \Magnitudes(m))+
theme_bw()


  ggplot()+ geom_point(data = so.df,aes(x = long,y = lat,size =剪切,颜色=剪切))
+ scale_size_manual(值=
c(8,6,4,2,1,2,4,6,8),guide =legend)+
coord_cartesian(xlim = c(-112.5,-104.25),ylim = c(33,44))+
scale_colour_brewer(type ='div',palette ='RdBu')


I am trying to map model/obs differences at locations in space. I have color mapped to the diff but I would also like to map size to diff. i'm currently mapping size to abs(diff) but it produces two different legends that I would like to combine. mapping size to diff creates small points for negative values and large points for positive values but I really only want the magnitude represented for over/under predictions. In case it makes a difference, I would also like the scales to be discrete. Thanks

Some test data:

so.df=data.frame(lat=runif(50,33,43),long=runif(50,-112,-104),diff=runif(50,-2,2))
    ggplot()+
        geom_point(data=so.df,aes(x=long,y=lat,color=diff,size=abs(diff)),alpha=0.8)+
scale_color_gradient2(low='red',mid='white',high='blue',limits=c(-0.6,0.6),breaks=c(-0.6,-0.4,-0.2,-0.1,0,0.1,0.2,0.6))+
        guides(color=guide_legend('SWE Differences (m)'),size=guide_legend('SWE Difference\nMagnitudes (m)'))+
        coord_cartesian(xlim=c(-112.5,-104.25),ylim=c(33,44))+
        theme_bw()

EDIT: to use a discrete color scale I'm using the following (open to suggestions)

so.df$cuts=cut_interval(so.df$diff,length=0.15)
ggplot()+
    geom_path(data=states,aes(x=long,y=lat,group=group),color='grey10')+
    geom_point(data=so.df,aes(x=long,y=lat,color=cuts,size=abs(diff)),alpha=0.8)+
    coord_cartesian(xlim=c(-112.5,-104.25),ylim=c(33,44))+
    scale_colour_brewer(type='div',palette='RdYlBu')+
    guides(color=guide_legend('SWE Differences (m)'),size=guide_legend('SWE Difference\nMagnitudes (m))+ 
    theme_bw()

解决方案

If you map your sizes to your cuts column and use scale_size_manual you can get the diverging size scale you want.

ggplot() + geom_point(data=so.df,aes(x=long,y=lat,size=cuts,color=cuts)) 
+ scale_size_manual(values =   
c(8,6,4,2,1,2,4,6,8),guide="legend") + 
coord_cartesian(xlim=c(-112.5,-104.25),ylim=c(33,44)) +   
scale_colour_brewer(type='div',palette='RdBu')

这篇关于发散尺寸比例尺ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆