2017-06-16 82 views
4

我有一个圆形阴谋,我想找到一种方法来删除中间的小白圈。去除中央白色圆圈?

这里是我的代码:

ggplot(d5)+geom_tile(aes(x=x, y=y, fill=xyz))+ 
    scale_y_continuous(expand=c(0,0),breaks=NULL,limits=c(0,3.6))+ 
    scale_fill_continuous(low="darkgreen", high="white")+ 
    coord_polar(start=-1*pi/2, direction=1)+ 
    theme_bw()+ 
    theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) 

千恩万谢。

+1

什么是'd5'?使用'dput(d5)' – Masoud

回答

2

我在这里做一个虚拟的例子:

require(dplyr) 
expand.grid(x = 1:20, y = 1:2) %>% 
    mutate(z = rnorm(length(x))) %>% 
    ggplot()+geom_tile(aes(x=x, y=y, fill=z))+ 
    scale_y_continuous(expand=c(0,0),breaks=NULL,limits=c(0,3.6))+ 
    scale_fill_continuous(low="darkgreen", high="white")+ 
    coord_polar(start=-1*pi/2, direction=1)+ 
    theme_bw()+ 
    theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) 

enter image description here

你是在正确的轨道与scale_ylimitsexpand参数上,你只需要找出其中的实际下限是。要做到这一点,让我们在没有coord_polar而没有scale_y的情况下绘制相同的图。

enter image description here

所以在我的例子中,瓷砖的最低边缘在y=0.5。所以你必须弄清楚你的最小值为y,然后减去geom_tile(这是1)的默认值height的一半。将该值用于较低的y限制,并且饼图中的洞将消失。

enter image description here

+0

谢谢,真正有用的信息。 –

+0

我想问一下设置刻度限制的方法,因为“Z”不固定。它可能是(死亡或幸存的)数据。两者的情节需要保持相同的规模,以使其具有可比性。 –

+0

@HamzaMezo,这应该有所帮助:https://stackoverflow.com/questions/22235580/how-to-get-multiple-ggplot2-scale-fill-gradientn-with-same-scale你只需要设置相同的“限制=''scale_fill'内的所有图。 – Brian

1

只是一个除了由@布赖恩给出了答案。
能够消除在中间的小的白色圆圈的y轴的正确限制可以如下计算:

library(dplyr) 
library(ggplot2) 
set.seed(4321) 
d5 <- expand.grid(x = 1:20, y = 1:2) %>% 
    mutate(z = rnorm(length(x))) 

yval <- sort(unique(d5$y)) 
h <- (yval[2] - yval[1])/2 
ylim_lo <- yval[1] - h 
ylim_up <- yval[2] + h 

ggplot(d5)+geom_tile(aes(x=x, y=y, fill=z))+ 
    scale_y_continuous(expand=c(0,0), breaks=NULL, limits=c(ylim_lo,ylim_up)) + 
    scale_fill_continuous(low="darkgreen", high="white") + 
    coord_polar(start=-1*pi/2, direction=1) + 
    theme_bw()+ 
    theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 

enter image description here

+0

太棒了,非常感谢。 –

+1

非常感谢您的帮助。请直到我如何upvote? –

+0

我想问一下如何设置刻度限制的方法,因为“Z”不是固定的。它可能是(死亡或幸存的)数据。两者的情节需要保持相同的规模,以使其具有可比性。 –