1

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

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.

enter image description here

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.

2
  • 2
    You could use geom_ribbon instead. Commented Jan 21, 2014 at 23:36
  • Thanks for your quick comments. I just found it. Commented Jan 21, 2014 at 23:38

1 Answer 1

2

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.