0

I'm currently learning R and ggplot2, but have encountered an issue I have no clue how to solve. I have a tidied dataset resembling the one in the picture (1). I'd like to plot the X entries against the Y entries in a scatterplot, so the 3 points would be: (1, 4), (2, 5), (3, 6).

The workaround I have so far is the following:

x <- tab %>% filter(Var == "X")
y <- tab %>% filter(Var == "Y")
plot(x ~ y)

This gives the plot I want, but I'd like to find a way to do it with ggplot if this is possible. Is this a problem with the way I apply the functions and formula or with the way my data is formatted for this case? Thank you greatly in advance, I'm very new to SO so apologies if my formatting is off.

  • 1
    You need to `pivot_wider`. [Here's the FAQ](https://stackoverflow.com/q/5890584/903061). A data set in the longest possible form isn't necessarily tidy. – Gregor Thomas Jun 14 '21 at 18:39
  • If you need more help than that, please share your data in a copy/pasteable format, not as a picture. `dput(tab)` is a nice way to make a copy/pasteable version of `tab` with all structure and class information included. – Gregor Thomas Jun 14 '21 at 18:41
  • Worked out great, thank you! The guide I had been following predated these new functions, thanks for pointing me towards them. – Rasmus Duret Jun 14 '21 at 19:13

0 Answers0