问题
I am trying to use facet_wrap to break up my data frame into individual plots based on one column. However, when I use levels, the title above each individual plot changes, but the data displayed in the chart does not.
Here's an example:
library(reshape2)
library(ggplot2)
levels(tips$sex) <- c("Male", "Female")
ggplot(tips, aes(x=total_bill, y=tip/total_bill))+
facet_wrap(~sex)+
geom_point(shape=1)
ggsave("prac.pdf")
This gives me a plot with Male on the left and Female on the right. The highest y data point is in the female graph.If I change the levels and have Female first, the Female label will appear on the left, but the highest y data point is now under male and still on the right.
levels(tips$sex) <- c("Male", "Female")
ggplot(tips, aes(x=total_bill, y=tip/total_bill))+
facet_wrap(~sex)+
geom_point(shape=1)
ggsave("prac.pdf")
Any suggestions? I'm working with a different data frame of values, but the above example shows the same problem that I am having.
来源:https://stackoverflow.com/questions/54756565/r-ggplot2-facet-wrap-isnt-changing-data-according-to-factor-level