Я приложил много усилий для создания новой переменной andel , которую я хочу визуализировать по порядку частоты с помощью ggplot2.
Я пишу:
ggplot(df,aes())+geom_col(mapping=aes(x=NYA_REGION, y=fct_infreq(andel)))
Я получаю сообщение об ошибке, утверждающее, что:
Error: `f` must be a factor (or character vector or numeric vector).
Я использовал каждый инструмент диагностики c в свое распоряжение и " Андел ", кажется, числовой вектор. В чем именно заключается проблема и как ее решить?
Repex:
structure(list(NYA_REGION = structure(2:11, .Label = c("UTANFÖR SVERIGE",
"ÖVRIGA LANDET", "STORGÖTEBORG", "oklart", "SÖDRA BOHUSLÄN",
"VÄSTERGÖTLAND", "VÄNERSBORG", "UDDEVALLA", "TROLLHÄTTAN", "DALSLAND",
"NORRA BOHUSLÄN"), class = c("ordered", "factor")), totstatus_tri = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("pågående studier",
"tidigt avbrott eller återbud", "sent avbrott"), class = c("ordered",
"factor")), ongoing = c(10L, 107L, 128L, 32L, 36L, 14L, 41L,
63L, 8L, 15L), antal = c(10L, 107L, 128L, 32L, 36L, 14L, 41L,
63L, 8L, 15L), andel = c(0.144927536231884, 0.36518771331058,
0.457142857142857, 0.450704225352113, 0.48, 0.4, 0.577464788732394,
0.456521739130435, 0.727272727272727, 0.681818181818182)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -10L), groups = structure(list(
NYA_REGION = structure(2:11, .Label = c("UTANFÖR SVERIGE",
"ÖVRIGA LANDET", "STORGÖTEBORG", "oklart", "SÖDRA BOHUSLÄN",
"VÄSTERGÖTLAND", "VÄNERSBORG", "UDDEVALLA", "TROLLHÄTTAN",
"DALSLAND", "NORRA BOHUSLÄN"), class = c("ordered", "factor"
)), .rows = list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))