geom_area绘制区域和轮廓ggplot [英] geom_area plot with areas and outlines ggplot

查看:340
本文介绍了geom_area绘制区域和轮廓ggplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个堆叠的geom_area图,但想用一条线勾划出每个区域图(在第一个红色区域但不是蓝色区域)。这是我最好的尝试,但我不知道如何使线型堆叠也。想法?

I am trying to make a stacked geom_area plot, but would like to outline each area plot (works on first 'red' area but not the blue) with a line. Here is my best attempt but I can't figure out how to make the line type stacked also. Ideas?

df= data.frame(Time=as.numeric(strsplit('1939 1949 1959 1969 1979 1989 1999 2009 2019 2029 2039 2049 1939 1949 1959 1969 1979 1989 1999 2009 2019 2029 2039 2049', split=' ')[[1]] ),
               Acres=as.numeric(strsplit('139504.2 233529.0 392105.3 502983.9 685159.9 835594.7 882945.1 1212671.4 1475211.9 1717971.7 1862505.7 1934308.0 308261.4 502460.8 834303.1 1115150.7 1430797.8 1712085.8 1973366.1 1694907.7 1480506.0 1280047.6 1164200.5 1118045.3', split=' ')[[1]] ),
               WUClass= strsplit('DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban Urban Urban Urban Urban Urban Urban Urban Urban Urban Urban Urban Urban', split=' ')[[1]]   
               )

a=ggplot(df,aes(x = Time,y = Acres,fill=WUClass))+ geom_area( position = 'stack'  )
plot(a)
a+ geom_line(aes(position = 'stack'))


推荐答案

要在该区域添加轮廓,只需更改颜色

To add an outline to the area, simply change the colour:

ggplot(df,aes(x = Time,y = Acres,fill=WUClass)) +
  geom_area( position = 'stack') +
  geom_area( position = 'stack', colour="black", show_guide=FALSE)

这样做:

ggplot(df,aes(x = Time, y = Acres, fill=WUClass, group=WUClass)) +
  geom_area() + geom_line(aes(ymax=Acres), position="stack")

这篇关于geom_area绘制区域和轮廓ggplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆