0

I tried to draw a scatter plot to describe the relationship between 理数 (the math grades) and 物理(the physics grades). However, I got a image without any points.....I don't know where is wrong. But I guess it's because the two numeric variables are not continuous ? If so, what should I do to get a right image??

 head(data1_s$理数)
[1] 148 148 144 142 138 145
 head(data1_s$物理)
[1]  98 102 103 103 100 100
 class(data1_s$理数)
[1] "integer"
 class(data1_s$物理)
[1] "integer"
ggplot(data1_s,aes(x="理数",y="物理"))+geom_point()

Elin
  • 6,507
  • 3
  • 25
  • 47
Li XinYi
  • 25
  • 3
  • 3
    Welcome, I'm confused because your title references categorical variables but your data seems to be integer. Can you look at the maximum and minimum values of the x and y axes and add them to your question? – Elin May 18 '19 at 14:09
  • Welcome to Stackoverflow: please try `aes(x=\`理数\`,y=\`物理\`)` – pogibas May 18 '19 at 14:10
  • 1
    [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a sample of data, all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. Right now we have neither your data nor your output, so we can't do much more than guess. But keep in mind that `ggplot2` uses bare column names, not quoted ones. – camille May 18 '19 at 14:43
  • You might need to first `reshape` your data. See the above comment and improve your question. – NelsonGon May 18 '19 at 15:59

1 Answers1

1

You might want to delete the quotations around your variable name. I generate a list of integers which fits your situation:

library(ggplot2)

理数 = sample(100:150, 20, replace=T)
物理 = sample(90:120, 20, replace=T)

> class(理数)
[1] "integer"

data = data.frame(理数, 物理)

ggplot(data, aes(x=理数, y=物理)) + geom_point()

enter image description here

Rachel Zhang
  • 562
  • 6
  • 20
  • 1
    OK! I'm sorry that I didn't accept your perfect answer in time~( because I am not very familiar with stack overflow~) – Li XinYi May 21 '19 at 12:26