R ggplot:如何根据组id更改垂直线的颜色(在极坐标图中)

R ggplot:如何根据组id更改垂直线的颜色(在极坐标图中),r,ggplot2,R,Ggplot2,我有以下数据帧(dput(df2)的输出): 我运行以下代码来绘制如下图: df2$y <- as.numeric(as.factor(df2$method)) + 3 df2$yend <- df2$y + 1 library(ggplot2) library(RColorBrewer) cx <- ggplot(df2, aes(y = y, x = angles)) cx + geom_point(aes(color = as.factor(id))) + ylim(

我有以下数据帧(dput(df2)的输出):

我运行以下代码来绘制如下图:

df2$y <- as.numeric(as.factor(df2$method))  + 3
df2$yend <- df2$y + 1

library(ggplot2)
library(RColorBrewer)
cx <- ggplot(df2, aes(y = y, x = angles))
cx + geom_point(aes(color = as.factor(id))) + ylim(0,6)  + theme_light() + scale_colour_brewer(palette = "Paired") +
  scale_x_continuous(labels = NULL, breaks = df2$angles)+coord_polar() + 
  theme(legend.position="none",  panel.border=element_blank(), axis.title =
        element_blank(), axis.text = element_blank())

df2$y我想这可能是你想要的(我知道,很久以前现在…)。有些地方我不太清楚,但尝试使用坐标网格线来显示数据几乎总是一个错误-使用geom_线或geom_段来显示数据,而留下网格线来显示坐标。这既解决了您对线条着色的需要,也使x网格线(即径向网格线)更容易获得您想要的标签(我不确定我是否正确理解了您的意思,关于“度v弧度”,我不确定)

库(ggplot2)
图书馆(RColorBrewer)
#您的“角度”看起来以弧度为单位,不确定如何将其转换为度?
#但是让我们设定轴标记的位置
溴
df2$y <- as.numeric(as.factor(df2$method))  + 3
df2$yend <- df2$y + 1

library(ggplot2)
library(RColorBrewer)
cx <- ggplot(df2, aes(y = y, x = angles))
cx + geom_point(aes(color = as.factor(id))) + ylim(0,6)  + theme_light() + scale_colour_brewer(palette = "Paired") +
  scale_x_continuous(labels = NULL, breaks = df2$angles)+coord_polar() + 
  theme(legend.position="none",  panel.border=element_blank(), axis.title =
        element_blank(), axis.text = element_blank())
library(ggplot2)
library(RColorBrewer)

# your "angle" looks to be in radians, not sure how you want these converted to degrees?
# but let's set where we want the axis marks to be
br <- seq(from = -pi, to = pi, length.out = 7)

ggplot(df2, aes(y = y, x = angles)) +
  geom_point(aes(color = as.factor(id))) + 
  theme_light() + 
  scale_colour_brewer(palette = "Paired") +
  geom_vline(aes(xintercept = angles, colour = truid)) +
  coord_polar() +
  scale_x_continuous(lim = c(-pi, pi), breaks = br, labels = 0:6 * 60)  +
  theme(legend.position="none",  
        panel.border=element_blank(), 
        axis.title = element_blank(), 
        axis.text.y = element_blank())