带有 R 的基本 hexbin?

发布于 2024-09-28 23:32:32 字数 822 浏览 2 评论 0原文

我有一项调查的结果。我正在尝试创建一个显示两个变量关系的图形:“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

如何使用此数据制作十六进制图? 我还应该考虑其他图表吗?

到目前为止的错误消息:

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

I have results from a survey. I am trying to create a graphic displaying the relationship of two variables: "Q1" and "Q9.1". "Q1" is the independent and "Q9.1" is the dependent. Both variables have responses from like scale questions: -2,-1,0,1,2. A typical plot places the answers on top of each other - not very interesting or informative. I was thinking that hexbin would be the way to go. The data is in lpp.
I have not been able to use "Q1" and "Q9.1" for x and y. However:

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

The values for Q1 are (hundreds of instances of): -2,-1,0,1,2

How can I make a hexbin graph with this data?
Is there another graph I should consider?

Error messages so far:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤星 2024-10-05 23:32:32

采取稍微不同的方法怎么样?将您的回答视为因素而不是数字怎么样?然后,您可以使用类似的方法来获取数据的潜在有用表示:

# 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。

How about taking a slightly different approach? How about thinking of your responses as factors rather than numbers? You could use something like this, then, to get a potentially useful representation of your data:

# 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()

You may want to switch q1 and q9 above, depending on the view of the data that you want.

爱殇璃 2024-10-05 23:32:32

也许 ggplot2 的 stat_binhex 可以为您排序?

另外,我发现 scale_alpha 对于处理过度绘图很有用。

Perhaps ggplot2's stat_binhex could sort that one for you?

Also, I find scale_alpha useful for dealing with overplotting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文