0
我正在嘗試爲每個方面(按性別)基於exercise = 0或exercise = 1創建兩個不同的行。第一個代碼沒有facet_wrap,基於性別的兩行代碼是不同的。第二個代碼是facet_wrap,兩行似乎是同一行。我怎樣才能改變代碼,使兩條線在每個方面都有所不同?如何根據每個方面的因子創建兩個不同的迴歸線? R,ggplot2
ggplot(cdc, aes(weight,wtdesire, color = exercise, group =
interaction(gender,exercise))) + geom_point(alpha = 1/5) +
geom_smooth(method = lm, aes(linetype=exercise))
生產:facet
然而,當我添加facet_wrap兩條線每個面似乎是相同的。
ggplot(cdc, aes(weight,wtdesire, color = exercise, group =
interaction(gender,exercise))) + geom_point(alpha = 1/5) +
geom_smooth(method = lm, aes(linetype=exercise)) + facet_wrap(~gender)
生產:second
你可能需要在第二個情節只使用'組=鍛鍊'。 – lbusett
@LoBu我也試過,但它沒有改變任何東西... –