geom_area 正在返回空图
geom_area is returning an empty graph
我想根据以下数据做一个水平衡图:
mes ND NDA T P N ETP Balanco pos neg
JAN 31 1 19.22581 232.3 13.347611 91.43498 140.865023 140.86502 0.000000
FEV 28 32 19.86429 114.3 12.999102 84.90256 29.397440 29.39744 0.000000
MAR 31 60 19.30968 141.5 12.460415 85.97512 55.524884 55.52488 0.000000
ABR 30 91 16.26000 201.2 11.498742 57.75492 143.445078 143.44508 0.000000
MAI 31 121 14.24839 83.6 10.167309 42.40138 41.198623 41.19862 0.000000
JUN 30 152 14.53667 123.0 8.741137 36.46793 86.532073 86.53207 0.000000
JUL 31 182 11.76452 44.0 8.477178 25.74084 18.259155 18.25916 0.000000
AGO 31 213 10.90645 2.5 9.678359 25.92338 -23.423384 0.00000 -23.423384
SET 30 244 14.25333 35.5 11.109252 44.86090 -9.360903 0.00000 -9.360903
OUT 31 274 16.77097 153.6 12.232699 66.82824 86.771759 86.77176 0.000000
NOV 30 305 18.59333 109.9 12.869165 80.71515 29.184855 29.18485 0.000000
DEZ 31 335 20.22903 121.0 13.288338 99.03102 21.968977 21.96898 0.000000
Link到数据:here.
使用geom_bar就可以了:
mensal$mes = factor(mensal$mes,
levels=c("JAN", "FEV", "MAR", "ABR", "MAI", "JUN",
"JUL", "AGO", "SET", "OUT", "NOV", "DEZ"))
ggplot(mensal) +
geom_bar(aes(x = mes, y = pos), stat = "identity", fill = "blue") +
geom_bar(aes(x = mes, y = neg), stat = "identity", fill = "red")
但是我想用区域,类似这样:
... 在那种情况下,使用 geom_area:
时我的图表返回空
ggplot(mensal) +
geom_area(aes(x = mes, y = pos), fill = "blue") +
geom_area(aes(x = mes, y = neg), fill = "red")
有什么想法吗?我做错了什么?
仅作为答案发布以防止错误信息:
gg <- ggplot(mensal, aes(group=1))
gg <- gg + geom_area(aes(x = mes, y = pos), fill = "blue")
gg <- gg + geom_area(aes(x = mes, y = neg), fill = "red")
gg <- gg + theme_bw()
gg <- gg + theme(panel.grid=element_blank())
gg <- gg + theme(panel.border=element_blank())
gg
我调整了一些其他的图表美学:
我想根据以下数据做一个水平衡图:
mes ND NDA T P N ETP Balanco pos neg
JAN 31 1 19.22581 232.3 13.347611 91.43498 140.865023 140.86502 0.000000
FEV 28 32 19.86429 114.3 12.999102 84.90256 29.397440 29.39744 0.000000
MAR 31 60 19.30968 141.5 12.460415 85.97512 55.524884 55.52488 0.000000
ABR 30 91 16.26000 201.2 11.498742 57.75492 143.445078 143.44508 0.000000
MAI 31 121 14.24839 83.6 10.167309 42.40138 41.198623 41.19862 0.000000
JUN 30 152 14.53667 123.0 8.741137 36.46793 86.532073 86.53207 0.000000
JUL 31 182 11.76452 44.0 8.477178 25.74084 18.259155 18.25916 0.000000
AGO 31 213 10.90645 2.5 9.678359 25.92338 -23.423384 0.00000 -23.423384
SET 30 244 14.25333 35.5 11.109252 44.86090 -9.360903 0.00000 -9.360903
OUT 31 274 16.77097 153.6 12.232699 66.82824 86.771759 86.77176 0.000000
NOV 30 305 18.59333 109.9 12.869165 80.71515 29.184855 29.18485 0.000000
DEZ 31 335 20.22903 121.0 13.288338 99.03102 21.968977 21.96898 0.000000
Link到数据:here.
使用geom_bar就可以了:
mensal$mes = factor(mensal$mes,
levels=c("JAN", "FEV", "MAR", "ABR", "MAI", "JUN",
"JUL", "AGO", "SET", "OUT", "NOV", "DEZ"))
ggplot(mensal) +
geom_bar(aes(x = mes, y = pos), stat = "identity", fill = "blue") +
geom_bar(aes(x = mes, y = neg), stat = "identity", fill = "red")
但是我想用区域,类似这样:
... 在那种情况下,使用 geom_area:
时我的图表返回空ggplot(mensal) +
geom_area(aes(x = mes, y = pos), fill = "blue") +
geom_area(aes(x = mes, y = neg), fill = "red")
有什么想法吗?我做错了什么?
仅作为答案发布以防止错误信息:
gg <- ggplot(mensal, aes(group=1))
gg <- gg + geom_area(aes(x = mes, y = pos), fill = "blue")
gg <- gg + geom_area(aes(x = mes, y = neg), fill = "red")
gg <- gg + theme_bw()
gg <- gg + theme(panel.grid=element_blank())
gg <- gg + theme(panel.border=element_blank())
gg
我调整了一些其他的图表美学: