如何在 ggplot2 中可视化两个分类变量
How to visualize two categorical variables in ggplot2
我试着画了一个散点图来描述理数(数学成绩)和物理成绩(物理成绩)之间的关系。但是,我得到了一张没有任何分数的图像.....我不知道哪里错了。但我想这是因为这两个数字变量不连续?如果是这样,我应该怎么做才能得到正确的图像?
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()
您可能想要删除变量名称两边的引号。
我生成了一个适合您情况的整数列表:
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()
我试着画了一个散点图来描述理数(数学成绩)和物理成绩(物理成绩)之间的关系。但是,我得到了一张没有任何分数的图像.....我不知道哪里错了。但我想这是因为这两个数字变量不连续?如果是这样,我应该怎么做才能得到正确的图像?
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()
您可能想要删除变量名称两边的引号。 我生成了一个适合您情况的整数列表:
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()