我具有从调查结果。我试图创建一个图形显示两个变量之间的关系:“Q1”和“Q9.1”。 “Q1”是独立的,“Q9.1”是相关的。这两个变量具有响应从规模类似的问题:-2,-1,0,1,2。一个典型的情节放在彼此顶部的答案 - 不是很有趣或信息。我在想,hexbin将要走的路。这些数据是在LPP。 我一直无法使用“Q1”和“Q9.1” x和y。但是:

> is.numeric("Q1")
[1] FALSE
q1.num <- as.numeric("Q1")
Warning message:
NAs introduced by coercion 

为Q1的值是(数百的实例):-2,-1,0,1,2

我怎样才能让这个数据hexbin图? 难道还有其他的图,我应该考虑什么?

错误消息到目前为止:

Warning messages:
1: In xy.coords(x, y, xl, yl) : NAs introduced by coercion
2: In xy.coords(x, y, xl, yl) : NAs introduced by coercion
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -Inf
有帮助吗?

解决方案

如何采取略有不同的方法?谈谈你的反应的思想为因素而不是数字?你可以使用这样的事情,然后,让你的数据的潜在有用的表示:

# Simulate data for testing purposes
q1 = sample(c(-2,-1,0,1,2),100,replace=TRUE)
q9 = sample(c(-2,-1,0,1,2),100,replace=TRUE)
dat = data.frame(q1=factor(q1),q9=factor(q9))
library(ggplot2)
# generate stacked barchart
ggplot(dat,aes(q1,fill=q9)) + geom_bar()

您可能需要开关Q1和Q9以上,这取决于所需的数据的视图。

其他提示

也许GGPLOT2的 stat_binhex 可能那种适合你?

另外,我发现 scale_alpha 获得处理overplotting有用的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top