This is an R HTML document. When you click the chunk like this:
Frequency Bar chart that counts the frequency of the items specified by the x aesthetics & plots it.library(tidyverse)
plot1 <- ggplot(mtcars, aes(x=cyl)) + geom_bar() + labs(title="Frequency bar chart") # Y axis derived from counts of X item print(plot1)
library(tidyverse) library(ggplot2) df <- data.frame(var=c("a", "b", "c"), nums=c(1:3)) plot2 <- ggplot(df, aes(x=var, y=nums)) + geom_bar(stat = "identity") # Y axis is explicit. 'stat=identity' print(plot2)
library(tidyverse) library(ggplot2) library(gridExtra)
plot1 <- ggplot(mtcars, aes(x=cyl)) + plot2 <- ggplot(df, aes(x=var, y=nums)) + grid.arrange(plot1, plot2, ncol=2)
## Error in `ggplot_add()`: ## ! Can't add `grid.arrange(plot1, plot2, ncol = 2)` to a <ggplot> object.
library(tidyverse) library(ggplot2) library(gridExtra) df <- data.frame(var=c("a", "b", "c"), nums=c(1:3)) ggplot(df, aes(x=var, y=nums)) + geom_bar(stat = "identity") + coord_flip() + labs(title="Coordinates are flipped")
library(tidyverse) library(ggplot2) library(gridExtra) df <- data.frame(var=c("a", "b", "c"), nums=c(1:3)) ggplot(df, aes(x=var, y=nums)) + geom_bar(stat = "identity") + coord_flip() + labs(title="Coordinates are flipped")