0

I'm running a basic plot function, but both the x and y axes only go from 1-5, so I want to show that a certain point is more frequent by increasing its size relative to the number of occurances. How would I accomplish this? I'm running base R.

plot(survey$Q24,survey$Q7, main = "X vs. Y",ylab = "Y",xlab = "X", pch = 20,bty = "l")

an image of my output: https://i.stack.imgur.com/GovwQ.png

dput(head(survey$Q7))

= c(5, 5, 4, 4, 5, 5)

dput(head(survey$Q24))

= c(1, 1, 1, 2, 1, 1)

  • Welcome to SO, Finn Murdoch! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jul 05 '22 at 21:02
  • @r2evans okay, I edited some more context in, Im not sure how I can add the data frame to the post without just pasting a bunch of numbers, I'm new to R, and stack overflow obviously – Finn Murdoch Jul 05 '22 at 21:15
  • If you run `dput(head(survey))` R will produce a code "recipe" which you can paste into your question, and which we can run to get an exact copy of the first 6 rows of your data frame. That can be extremely useful for diagnosing issues and testing possible solutions, since it allows others to use data in the same formats that you have it. – Jon Spring Jul 05 '22 at 21:17
  • If you have lots of other columns unrelated to the question, you could include instead a smaller data frame with just these two columns: `dput(head(data.frame(Q24 = survey$Q24, Q7 = survey$Q7)))` – Jon Spring Jul 05 '22 at 21:19
  • @JonSpring I added the dput for both relevant columns, let me know if that helps – Finn Murdoch Jul 05 '22 at 21:25

1 Answers1

0

enter image description hereLet's say the number of occurences is y (or head(survey$Q24)), then:

x = c(5, 5, 4, 4, 5, 5)
y = c(1, 1, 1, 2, 1, 1)

plot(x,y, main = "X vs. Y",ylab = "Y",xlab = "X", pch = 20, bty = "l", cex = y)

cex is the parameter that will determine the size of the points in your plot.

Fla28
  • 197
  • 11