刻度散点图ggplot

时间:2019-05-07 09:56:26

标签: r ggplot2 scatterpie

我有这个数据

structure(list(year = c("2018", "2018", "2018", "2018", "2018", 
"2018", "2018", "2018", "2018", "2018", "2018", "2018"), month = c(1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), Avdischarge = c(906.5947917, 
511.2469444, 364.0697222, 268.3026389, 141.5931944, 142.0445486, 
37.53111111, 34.68916667, 35.50809028, 26.94083333, 40.400381945, 
312.0436806), IndustrialCompound = c(0.729166666666667, 0.815789473684211, 
0.818181818181818, 0.771428571428571, 0.736842105263158, 0.761904761904762, 
0.780487804878049, 0.829268292682927, 0.8, 0.780487804878049, 
0.738095238095238, 0.731707317073171), Pharmaceutical = c(0.145833333333333, 
0.105263157894737, 0.113636363636364, 0.142857142857143, 0.131578947368421, 
0.119047619047619, 0.121951219512195, 0.0975609756097561, 0.114285714285714, 
0.146341463414634, 0.166666666666667, 0.195121951219512), Pesticide = c(0.125, 
0.0789473684210526, 0.0681818181818182, 0.0857142857142857, 0.131578947368421, 
0.119047619047619, 0.0975609756097561, 0.0731707317073171, 0.0857142857142857, 
0.0731707317073171, 0.0952380952380952, 0.0731707317073171), 
    TotalOvershootings = c(0.48, 0.558823529411765, 0.619718309859155, 
    0.538461538461538, 0.612903225806452, 0.591549295774648, 
    0.561643835616438, 0.554054054054054, 0.538461538461538, 
    0.577464788732394, 0.617647058823529, 0.694915254237288)), row.names = 37:48, class = "data.frame")

我正在尝试绘制一些散点图,但是我没有正确地获得馅饼。 我用了这个:

pie<-ggplot()+geom_scatterpie(aes(x=month, y=2, group=type, r = TotalOvershootings/5), 
                                        cols= c("IndustrialCompound", "Pharmaceutical", "Pesticide"),alpha= 0.7, color=NA,
                                        data= counts)

我明白了:

pies

每次我更改r时,派只会变稀。如果我离开r = TotalOvershootings,我的大馅饼就会重叠。

我可以更改些什么,以便使馅饼好吃?每次更改r时,我都希望看到圆形的饼图,而不是椭圆形。

1 个答案:

答案 0 :(得分:1)

显然,您只需要使用coord_fixed()

ggplot()+
geom_scatterpie(aes(x=month, y=2, r=TotalOvershootings/1.35),
                cols= c("IndustrialCompound", "Pharmaceutical", "Pesticide"), 
                alpha= 0.7, color=NA, data= counts)+
coord_fixed()

enter image description here