Drawing flipped Normal distribution in R without using coord_flip()

余生长醉 提交于 2019-12-10 22:57:03

问题


Good day

Without using coord_flip(), Is there a way to draw normal distribution flipped by exchanging position x and y in aes()? I' ve tried as below.

df3 <- data.frame(x=seq(-6,6,b=0.1),y=sapply(seq(-6,6,b=0.1),function(x) dnorm(x))) 
ggplot(df3,aes(y,x))+ geom_line()  # x,y position exchanged

回答1:


I'm not sure what's wrong with coord_flip, but you can avoid it with geom_path. geom_path connects the points in the order they appear in the data, rather than in order of the magnitude of the x-value. So you just need to make sure the data are ordered by y-axis value (which they already are here).

ggplot(df3, aes(y,x)) + 
  geom_path() +
  theme_classic()



来源:https://stackoverflow.com/questions/44621474/drawing-flipped-normal-distribution-in-r-without-using-coord-flip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!