如何在R中使用渐变颜色和形状在散点图上放置边框? [英] How to Place a border around points for the scatter plot with gradient color and shape in R?

查看:1414
本文介绍了如何在R中使用渐变颜色和形状在散点图上放置边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是围绕散点图中的点放置边界,其中渐变色渐变形基于该值(您可以在以下脚本中看到)。

  ggplot(filname,aes(Va1,Var2,col = PR,size = PR))+ 
geom_point()+
labs(list(title =Title,y =Var2,x =Var1))+
xlim 0,150)+
scale_color_gradientn(colors = rainbow(7))+
scale_x_continuous(breaks = seq(0,150,12))

** PR是第三瓦尔在我的数据。

生成的图
p>

我在这里发现了以下问题:




  • 任何帮助都非常感谢?

    解决方案

    我认为您需要做的就是使用一个尊重填充颜色的形状。形状21:25有这个属性,


    My goal is to place the border around points in scatter plot WHICH has the gradient color and gradient shape based on the value (as you can see in following script).

    ggplot(filname, aes(Va1, Var2, col= PR, size=PR)) +
      geom_point() +
      labs(list(title = "Title", y = "Var2", x = "Var1")) +
      xlim(0, 150) +
      scale_color_gradientn(colours = rainbow(7)) +
      scale_x_continuous(breaks=seq(0, 150, 12))
    
    ** PR is the third Var in my data. 
    

    The generated plot

    I found the following questions here:

    but really they do not work in my case due to the two reasons I bolded above, I want to keep the gradient color and gradient shape but at the same time add the border around the points to make them more appreciable.

    Basically, to make outline colour in ggplot I found we would have :

    1. fill
    2. colour for border

    Considering this when I act accordingly as below

    ggplot(PR_Grt100_REL_80, aes(Age, SC, col= PR, size=PR)) + 
      geom_point(aes (fill= PR), colour = "black") +
      labs(list(title = "Title", y = "Var2", x = "Var1")) +
      xlim(0, 150) +
      scale_color_gradientn(colours = rainbow(7)) +
      scale_x_continuous(breaks=seq(0, 150, 12))
    

    I would get the following graph!

    Any help is highly appreciated?

    解决方案

    I think all you need to do is to use a shape that respects fill and color. Shapes 21:25 have this property, http://sape.inf.usi.ch/quick-reference/ggplot2/shape.

    Using mtcars:

    library(ggplot2)
    ggplot(mtcars, aes(mpg, hp, fill = cyl, size = cyl)) +
        geom_point(shape = 21, stroke = 2) + # change the thickness of the boarder with stroke
        scale_fill_gradientn(colours = rainbow(7)) +
        scale_size(range = c(2,6)) # only for example visibility
    

    这篇关于如何在R中使用渐变颜色和形状在散点图上放置边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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