0

I'm new to R and I was trying to shift my plotting platform from something like Excel to R/ggplot2.

I'm having a difficult time making the scatter plot points join smoothly. I have some data:

p1 <- ggplot(DunnTib, aes(Vf, CV3, col = Rsq))+
  geom_line()+
  theme_bw()
p1

And the result it generates is something like this: ggplot2 result

The plot as I made it in Excel was much smoother: Excel 2013 result

I tried using geom_path() as well as geom_line() and adjusting the size but haven't found a better solution. Any tips on how to achieve the same level of smoothness

Edit: I've shared the complete data on Google Drive [link]. The lack of smoothness is more pronounced when a lot of points are used because they are so close together.

I also tried geom_path() and while this is the kind of shape I want, a crisper line as it was in Excel would be preferable.

p1 <- ggplot(DunnTib, aes(Vf, CV3)) +
  geom_path(size = 2, col = 'red')+
  theme_bw()
p1

geom_path plot

Edit: I've found a solution to my own question so I thought I'd add it here. What you're looking for is anti-aliasing. ggplot doesn't do anti-aliasing but a package called Cairo does. Read about it here

R Walser
  • 330
  • 3
  • 16
  • Make `Rsq` a factor. That is, `.. col = as.factor(Rsq))`. Look at the scale, then you see it is numeric. – markus Jan 10 '22 at 09:20
  • @markus I tried that but what I get is a list of swatches with the Rsq (R-Squared) values. I replaced it with `col = 'Red'` and used `geom_path()` and the result is much better in terms of smoothness but still not as much as I was hoping for. – R Walser Jan 10 '22 at 09:53
  • you can also try ggalt's x-spline function. – Roman Jan 10 '22 at 11:15
  • 1
    Please post reproducible data so that other contributors can provide solutions. You can paste a data structure using the `dput(DunnTib)` function. – dshkol Jan 10 '22 at 11:41
  • I've shared the complete data set (700 rows) via google drive. I used `dput()` to generate a subset but felt that the problem was more evident when a larger data set is used because the points are so close. – R Walser Jan 11 '22 at 04:08

0 Answers0