r - geom_area区域和轮廓图ggplot

标签 r ggplot2

我正在尝试绘制堆叠的geom_area图,但想用一条线勾勒出每个区域图(在第一个“红色”区域而不是蓝色区域工作)。这是我的最佳尝试,但我不知道如何将线型也堆叠起来。有想法吗?

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'))

最佳答案

要将轮廓添加到该区域,只需更改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")

关于r - geom_area区域和轮廓图ggplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12323060/

相关文章:

R 计算公式列表中的公式

r - r 中某些值的具有自己颜色的热图图

r - 如何在R中生成偏态正态分布的随机数?

r - 在 ggplot 中绘制 RDA(素食主义者)

r - 在 qqplot 中的多个图上绘制多个子图

r - 在 ggplot2 中的 geom_bar 顶部显示总数的百分比,同时在 y 轴上显示计数

r - 基于另一个数据帧规范化数据帧

class - 如何使用 Roxygen2 正确记录 S4 类插槽?

r - 使用 `grid.arrange` 保留文本大小

r - 图例上的ggplot2边框但条形图中没有