[英]How to do a scatter plot with factor class on Xlim?
When I try to do a scatter plot with jitter, i found it require the Xlim
to be numeric当我尝试使用抖动绘制散点图时,我发现它要求Xlim
为数字
plot(jitter(d$'WHO region'), d$Numeric)
> Error in jitter(d$"WHO region") : 'x' must be numeric
so when I try to change the column to numeric, the output on scatter with jitter became unreadable因此,当我尝试将列更改为数字时,带有抖动的 scatter 输出变得不可读
as.numeric(as.character(d$'WHO region'))
Please be aware that the WHO region column is Factor as i found character class does not work with scatter plot.请注意 WHO region 列是 Factor 因为我发现字符类不适用于散点图。
Below is the code i used to input the data下面是我用来输入数据的代码
d <- read_csv("WHOSIS_000008.csv", col_types = cols(`WHO region` = col_factor(levels = c("Africa","Americas", "Eastern Mediterranean","Europe", "South-East Asia", "Western Pacific"))))
The result I am supposed to get.我应该得到的结果。
Using the iris
data set and stripchart
this is pretty close:使用iris
数据集和stripchart
这非常接近:
data(iris)
stripchart(Sepal.Length~Species, iris, method="jitter", vertical=TRUE, pch=16, col="blue")
mns <- with(iris, tapply(Sepal.Length, Species, mean))
segments((1:3)-.1, mns, (1:3)+.1, mns, lwd=3, col="red")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.