问题
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