我希望從每組“drafted_qbs”中按“season_pts”的順序顯示多個 geom_points。但問題是我不確定如何分配另一個變數。我有一個“團隊”列,它只是每個組的行號,但只會對第一個分組“2”進行排序。
任何按點順序排列在同一圖表上的方式(對分面不感興趣)每個組“fantasy_pts”都會有所幫助。
資料
structure(list(team = c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L,
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L),
season_pts = c(447.44, 381.62, 416.6, 367.96, 419.92, 490.78,
501.66, 458.56, 484.48, 458.36, 518, 495.7, 511.34, 499.68,
536.42, 522.92, 536.92, 518.46, 538.06, 525.96, 541.84, 523.26,
542.98, 527.4, 527), drafted_qbs = c(2, 2, 2, 2, 2, 3, 3,
3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -25L))
uj5u.com熱心網友回復:
問問自己“我想用這個情節展示什么?”通常會有所幫助。
如果您試圖表明增加的 QB 數量往往會產生更多的點數,那么您可以執行以下操作:
ggplot(df, aes(drafted_qbs, season_pts))
geom_point(size = 4, aes(color = factor(team)))
geom_smooth(color = 'gray20', size = 0.5, linetype = 2, alpha = 0.15)
scale_color_brewer(palette = 'Set1')
theme_light(base_size = 16)
labs(x = 'Drafted QBs', y = 'Season Points', color = 'Team')
theme(panel.grid.minor.x = element_blank())
如果您想表明并非所有團隊都受到這種影響的同等影響,那么這樣的事情可能更可取:
ggplot(df, aes(team, season_pts, color = drafted_qbs))
geom_point(size = 4, alpha = 0.5)
scale_color_gradient(low = 'red3', high = 'blue3')
theme_light(base_size = 16)
labs(x = 'Team', y = 'Season Points', color = 'Drafted QBs')
theme(panel.grid.minor.x = element_blank())
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491046.html