简体   繁体   English

将不同的 colors 赋予 R 中散点 plot 上不同间隔的点

[英]Giving different colors to the dots that are in different intervals on a scatter plot in R

I am a beginner in R and would like to give different colors to the dots in my scatter plot, between 0 -> 0.4, 0.4 ->0.8 and 0.8 -> 1 in my x-axis.我是ZE1E1D3D40573127E0480CAF1283D6Z的初学者,并希望给出不同的Z62848E3CE5804AA985513A792FFFF87B2Z在我的散布Z32FA6E1B78ANA飞机中的点数i have googled a lot but was not able to find hints for the solution.我用谷歌搜索了很多,但无法找到解决方案的提示。

i am using this code for the plot:我正在将此代码用于 plot:

ggplot(xlim=1, ylim=1,)+geom_point(data=df,aes(x1,y1))+
  geom_circle(aes(x0 = x0, y0 = y0 ,r = r,colour=cb), data = circ_kv) +
  coord_fixed(xlim=c(0,1),ylim=c(0,1))

all help or hints are very much appreciated!非常感谢所有帮助或提示!

this is the scatter plot i am working with这是我正在使用的散点图 plot

Something like this?像这样的东西?

library(tidyverse)

set.seed(1337)

data <- tibble(
  x = runif(300),
  y = runif(300)
)
  
data %>%
  mutate(
    # distance to origin
    r = sqrt(x**2 + y**2),
    r_group = case_when(
      r < 0.4 ~ "group 1",
      r < 0.8 ~ "group 2",
      r < 1.0 ~ "group 3"
    )
  ) %>%
  ggplot(aes(x,y, color = r_group)) +
    geom_point() +
    coord_fixed()

Created on 2021-12-09 by the reprex package (v2.0.1)reprex package (v2.0.1) 于 2021 年 12 月 9 日创建

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

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