我正在嘗試使用 facet_wrap 制作一個 ggplot,但由于某種原因,某些子圖有時不顯示并顯示為空白。
library(plotly)
peak_season <- drop_na(read_csv(url("https://www.dropbox.com/s/wb8qmrcul197ypp/peak_season.csv?raw=1")))
ggplotly(
ggplot(data = peak_season, aes(x = overall, frame = age))
geom_bar(position = "identity") facet_wrap(~league_name_clean)
)
# Need to add position = "identity" due to a well known bug in ggplotly and geom_bar.

資料可用于繪制繪圖,如圖所示。對于西班牙甲級聯賽,肯定有 20 歲球員的資料。
ggplotly(
ggplot(data = peak_season %>% filter(league_name_clean == "Spain Primera Division"), aes(x = overall, frame = age))
geom_bar(position = "identity") facet_wrap(~league_name_clean)
)
# Just added a filter

我讓它與 gganimate 一起作業,但我希望我的用戶能夠控制和探索顯示的資料。
library(gganimate)
ggplot(data = peak_season, aes(x = overall))
geom_histogram(binwidth = 1) facet_wrap(~league_name_clean)
transition_states(age, state_length = 1)
view_follow(fixed_y = TRUE)
labs(title = "Player peak age by league",
y = "No. of players",
subtitle = "Age: {closest_state}")

我嘗試使用 RStudio Cloud 在我的計算機中推出一個錯誤,但它發生了同樣的事情。
任何想法為什么會發生這種情況?
謝謝,
uj5u.com熱心網友回復:
對于將來可能會發現這一點的任何人,我認為 ggplotly 不夠強大,無法計算如此多的圖 每個整體 - 年齡 - 聯賽的頻率,所以我必須事先計算它。
t <- peak_season %>%
select(overall, age, league_name_clean) %>%
table() %>%
as_tibble
ggplotly(
ggplot(data = t, aes(x = Overall, y = Count, frame = age))
scale_x_discrete(breaks = seq(40, 100, by = 5))
geom_col(position = "identity") facet_wrap(~league_name_clean)
)

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/403331.html
標籤:
上一篇:將箱線圖分組在一起
