I'm trying to plot a bar graph from a data frame. The bar heights are all being returned as 1. Below is a sample of reproducible code:
df <- data.frame(country = c("China", "USA", "South Korea"),
confirmed = c(4747763, 90, 2060))
ggplot(df, aes(x = country, fill = country)) +
geom_bar()
Why aren't the bar heights matching to the numeric values in the column "confirmed" in my data frame?
Got it. Have to set stat = "identity" to have geom_bar read the y-axis:
df %>%
ggplot(aes(x = country, y = confirmed)) +
geom_bar(stat = "identity")