使用ggplot2可变的行大小 [英] Variable line size using ggplot2

查看:96
本文介绍了使用ggplot2可变的行大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用连续变量改变行的大小。现在我用美学大小的geom_line。例如:

I would like to change the line size with a continuous variable. Now I used the geom_line with aesthetics size. For example:

x <- 1:100
y <- x * x 
z <- abs(cos(x * pi / (max(x))))

df <- data.frame(x = x, y = y, z = z)
library(ggplot2)

ggplot(df, aes(x, y, size = z)) + geom_line()

但分段之间有一些空格(请参阅下图,请放大以查看空格)。看起来ggplot2使用矩形来绘制每个段。

But there are some spaces among segments (see figure below. Please zoom in to see the spaces). it seems ggplot2 uses rectangles to plot each segment.

我增加了点数,但空间直到存在大曲率。

I have increased the point number, but spaces till exist for bigger curvature.

我的问题是如何去除这些空间。我非常感谢你的任何建议。

My question is how to remove these spaces. I really appreciate it for any suggestions.

推荐答案

根据您的喜好调整乘数:

Adjust the multiplier to your preference:

mult <- 200
ggplot(df, aes(x, y)) + geom_line() + geom_ribbon(aes(ymin=y-mult*z, ymax=y+mult*z))

这篇关于使用ggplot2可变的行大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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