geom_bar 返回计数 1
geom_bar returning a count of 1
我正在尝试根据数据框绘制条形图。条形高度全部返回为 1。以下是可重现代码的示例:
df <- data.frame(country = c("China", "USA", "South Korea"),
confirmed = c(4747763, 90, 2060))
ggplot(df, aes(x = country, fill = country)) +
geom_bar()
为什么条形高度与我的数据框中 "confirmed" 列中的数值不匹配?
知道了。必须设置 stat = "identity" 才能让 geom_bar 读取 y 轴:
df %>%
ggplot(aes(x = country, y = confirmed)) +
geom_bar(stat = "identity")
我正在尝试根据数据框绘制条形图。条形高度全部返回为 1。以下是可重现代码的示例:
df <- data.frame(country = c("China", "USA", "South Korea"),
confirmed = c(4747763, 90, 2060))
ggplot(df, aes(x = country, fill = country)) +
geom_bar()
为什么条形高度与我的数据框中 "confirmed" 列中的数值不匹配?
知道了。必须设置 stat = "identity" 才能让 geom_bar 读取 y 轴:
df %>%
ggplot(aes(x = country, y = confirmed)) +
geom_bar(stat = "identity")