R 移除极坐标图(ggplot2)的最外环

R 移除极坐标图(ggplot2)的最外环,r,ggplot2,polar-coordinates,R,Ggplot2,Polar Coordinates,我正试图构建一个极坐标图,以显示特定方向上的百分位数,但在移除极坐标图最外层的环时遇到了困难,尽管它已作为帮助构建极坐标图的条形图的一部分被移除 以下是可复制代码: library(ggplot2) perc_df=data.frame(id=c(125,126,127,128,129,130),percentile=c(.50,.75,.99,.27,.12,.66)) cxc <- ggplot(perc_df, aes(x = id)) + geom_bar(width =

我正试图构建一个极坐标图,以显示特定方向上的百分位数,但在移除极坐标图最外层的环时遇到了困难,尽管它已作为帮助构建极坐标图的条形图的一部分被移除

以下是可复制代码:

library(ggplot2)

perc_df=data.frame(id=c(125,126,127,128,129,130),percentile=c(.50,.75,.99,.27,.12,.66))

cxc <- ggplot(perc_df, aes(x = id)) +
  geom_bar(width = 1, aes(weight = percentile, fill = ..count..)) +
  scale_y_continuous(limits = c(0,1),breaks=seq(0, 1, .25),expand=c(0,0)) +
  scale_fill_gradient2(low = 'red', high = 'green',mid='yellow', limits=c(0,1),midpoint=.5,guide = "colourbar")

cxc + coord_polar(theta = 'x',start = 2.6)+ guides(fill=FALSE) +
  theme(axis.title.x=element_blank(),axis.text.x=element_blank(),axis.ticks.x=element_blank(),axis.title.y=element_blank(),
        axis.text.y=element_blank(),axis.ticks.y=element_blank(),plot.title = element_text(lineheight=.8, face="bold",hjust = 0.5),
        panel.border = element_blank())
库(ggplot2)
perc_df=data.frame(id=c(125126127128129130),百分位数=c(.50、.75、.99、.27、.12、.66))

这个问题的答案很简单。您必须添加
geom\u hline
(您可能需要在添加
geom\u bar
之前添加它们)。我认为在你的例子中,
geom_vline
没有意义,因为x轴上的变量不是数字

我加了一行:

geom_hline(yintercept = seq(0, 1, by = 0.25), colour = "grey90", size = 0.2)
整个代码如下所示:

perc_df <- data.frame(id = c(125, 126, 127, 128, 129, 130), 
                      percentile = c(0.50, 0.75, 0.99, 0.27, 0.12, 0.66))

library(ggplot2)
ggplot(perc_df, aes(id)) +
    geom_hline(yintercept = seq(0, 1, by = 0.25), colour = "grey90", size = 0.2) +
    geom_bar(aes(weight = percentile, fill = ..count..), 
             width = 1, ) +
    scale_y_continuous(limits = c(0, 1), 
                       breaks = seq(0, 1, 0.25),
                       expand = c(0, 0)) +
    scale_fill_gradient2(low = "red", mid="yellow", high = "green", 
                         limits = c(0, 1), midpoint = 0.5, 
                         guide = "colourbar") +
    coord_polar(theta = "x", start = 2.6) + 
    guides(fill = FALSE) +
    theme_bw() +
    theme(axis.title = element_blank(),
          panel.border = element_blank(),
          legend.key = element_blank(),
          axis.ticks = element_blank(),
          axis.text = element_blank(),
          panel.grid  = element_blank(),
          plot.title = element_text(lineheight = 0.8, face = "bold", 
                                    hjust = 0.5))

perc_df这个问题的答案很简单。您必须添加
geom\u hline
(您可能需要在添加
geom\u bar
之前添加它们)。我认为在你的例子中,
geom_vline
没有意义,因为x轴上的变量不是数字

我加了一行:

geom_hline(yintercept = seq(0, 1, by = 0.25), colour = "grey90", size = 0.2)
整个代码如下所示:

perc_df <- data.frame(id = c(125, 126, 127, 128, 129, 130), 
                      percentile = c(0.50, 0.75, 0.99, 0.27, 0.12, 0.66))

library(ggplot2)
ggplot(perc_df, aes(id)) +
    geom_hline(yintercept = seq(0, 1, by = 0.25), colour = "grey90", size = 0.2) +
    geom_bar(aes(weight = percentile, fill = ..count..), 
             width = 1, ) +
    scale_y_continuous(limits = c(0, 1), 
                       breaks = seq(0, 1, 0.25),
                       expand = c(0, 0)) +
    scale_fill_gradient2(low = "red", mid="yellow", high = "green", 
                         limits = c(0, 1), midpoint = 0.5, 
                         guide = "colourbar") +
    coord_polar(theta = "x", start = 2.6) + 
    guides(fill = FALSE) +
    theme_bw() +
    theme(axis.title = element_blank(),
          panel.border = element_blank(),
          legend.key = element_blank(),
          axis.ticks = element_blank(),
          axis.text = element_blank(),
          panel.grid  = element_blank(),
          plot.title = element_text(lineheight = 0.8, face = "bold", 
                                    hjust = 0.5))

perc_df您能否更具体地说明您链接到的答案中哪些不起作用?对我来说,这看起来像是那个问题的重复。你能更具体地说明你链接到的答案中哪些不起作用吗?这看起来像是那个问题的重复。不确定我做错了什么,尝试了非常相似的代码,谢谢!不确定我做错了什么,试过的代码非常相似,谢谢!