我正在努力改變回歸
- 代碼是:
data %>%
# filter(!is.na(IND_TEST_SCORE) & !is.na(SCORE)) %>%
ggplot(., aes(x = IND_TEST_SCORE, y = SCORE,
color = TYPE, linetype = TYPE, shape = TYPE))
geom_point(alpha = 0.1, color = "red")
scale_shape_manual(values = c(16, 17)) ## change shape type
stat_smooth(formula = y ~ x, method = lm, se = T)
scale_linetype_manual(values = c("solid", "dashed"))
scale_color_manual(values = c(A = "yellow", B = "cadetblue2"),
label = c(A = "TYPE A", B = "TYPE B"))
# scale_linetype(name = "Type:")
# facet_grid(~TYPE)
labs(x = "IND_TEST_SCORE",
y = "SCORE",
title = "Effect of IND_TEST_SCORE and TYPE on SCORE",
color = "Type:")
theme_bw()
問題:
- 1匹配顏色
scale_color_manual到TYPE - 2將圖例與定義的線型匹配
scale_linetype_manual - 3將圖例與
shapes線型與顏色匹配 - 4擺脫重復的傳說
ps:我在這里和
PS-您還可以通過添加fill = Type:、設定 alpha 級別stat_smooth()以及使用手動色標來為顏色和填充添加以下內容來為錯誤帶著色aesthetics = c("color", "fill"):
data %>%
mutate(`Type:` = paste("TYPE", TYPE)) %>%
ggplot(aes(x = IND_TEST_SCORE, y = SCORE,
color = `Type:`, fill = `Type:`, linetype = `Type:`, shape = `Type:`))
geom_point(alpha = 0.25)
scale_shape_manual(values = c(16, 17)) ## change shape type
stat_smooth(formula = y ~ x, method = lm, se = T, alpha = .15)
scale_linetype_manual(values = c("solid", "dashed"))
scale_color_manual(values = c("yellow", "cadetblue2"), aesthetics = c("color", "fill"))
labs(x = "IND_TEST_SCORE",
y = "SCORE",
title = "Effect of IND_TEST_SCORE and TYPE on SCORE")
theme_bw()

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/529685.html
上一篇:在條形圖上以百分比水平繪制
