so i have a开发者_开发问答 vector with Themes for example: Gore, Military, Survival Parody, Super Power Love Polygon, Video Game
I want to create a barplot showing the number of times each Themes is showing. I used: dummy_cols(Alldata2, select_columns = "Themes",split=",") This create a matrix and not sure how can I barplot it
I used the code above to create the dummies however not sure hot can I barplot for all Themes. The list has 24,000 lines and according to the dummies a total of 52 Themes. Themes Thanks
No need to create a dummy matrix. Using ggplot2
you could get a basic barchart of the counts using a geom_bar
like so:
set.seed(123)
Alldata2 <- data.frame(
Themes = sample(c("Gore", "Military", "Survival Parody", "Super Power Love Polygon", "Video Game"), 100, replace = TRUE)
)
library(ggplot2)
ggplot(Alldata2, aes(x = Themes)) +
geom_bar()
Until some weeks ago (before ggplot2 3.4.0 2022/11/07) qplot
would have been an alternative, here:
Note: qplot
was deprecated in ggplot2 3.4.0.
Data taken from @stefan (many thanks!)
library(ggplot2)
qplot(x=Themes, data = Alldata2)
精彩评论