我有一个包含数千行和18个变量的大数据集。当我正在做的是改变X轴上的变量时,需要永远制作17个单独的图。让我们假装就是这样:
install.packages("ggplot2")
library(ggplot2)
variable1 <- c("no","yes","no","no")
variable2 <- c("low", "medium", "medium", "high")
variable3 <- c("horrible", "bad", "terrifying", "pretty")
variable4 <- c("hm", "why", "cheese", "wine")
newish <- data.frame(variable1, variable2, variable3, variable4)`
有没有办法从这个代码块中大量生产(对于变量2,3等)我喜欢的美学?
plot1 <- ggplot(newish, aes(variable1, ..count..)) + geom_bar(aes(fill = Class), position = "dodge") +
ggtitle("Lunar Phase and Accident Outcome") +
theme(plot.title = element_text(hjust = 0.5)) +
xlab("Lunar Phase") +
ylab("Accident Count")
然后我就用多色图在同一个窗口上绘制它们。