2017-09-29 6 views
0

막대 그래프의 일부로 제거되었지만 극좌표의 바깥 쪽 반지를 제거하는 데 문제가 있지만 특정 방향으로 백분위 수를 보여주기 위해 극좌표를 작성하려고합니다. 극지 음모를 만드는 데 도움이됩니다.극좌표의 가장 바깥 고리 제거 (ggplot2)

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()) 

이 생산되는 것입니다 : 여기

는 재현 코드

radar

이 아주 가까이 있지만 우리가 하나의 백분위가의 마지막 원에되고 싶어 플롯의 외측 링을 갖기보다는 음모를 꾸미십시오.

편집 : 이미 답변을 포함 시키려고했지만 행운도 없습니다. Remove extra space and ring at the edge of a polar plot

+0

는 당신이 더 구체적 일 수 있습니다 당신이 연결 한 대답에서 작동하지 않는 것은 무엇입니까? 이 질문은 저에게 중복 된 것 같습니다. – aosmith

답변

2

그 대답은 매우 간단합니다. geom_hline을 추가해야합니다 (geom_bar을 추가하기 전에 추가하기를 원할 것입니다). x 축상의 변수가 숫자가 아니기 때문에 geom_vline이 귀하의 경우에 적합하다고 생각하지 않습니다.

나는 한 줄을 추가 :

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)) 

를 그리고이 같은 플롯을 생성합니다

enter image description here

+0

내가 뭘 잘못하고 있는지, 코드를 매우 비슷하게했는지, 고마워! – BaseballR

+0

@BaseballR Happens :-) 도움이된다면 내 대답을 받아 들일 수 있습니다. – PoGibas