- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个数据集,其中包含 x、y 和 z (resp
) 值以及用于分面的两列,以便创建平铺图网格。
dput()
的输出在文末。
library(ggplot2)
我的实际数据集在变量之间有六个独特的相互作用,但为简单起见,我将其限制为四个。我可以用每个独特的组合创建一个瓷砖图,但不能用整个组合。 dput()
的输出在文章的末尾。我认为这可能与需要通用 y 轴刻度的 ggplot
有关,但这不是问题所在。
library(ggplot2)
p <- ggplot(data_sub, aes(x = x, y = y)) + geom_tile(aes(fill = resp))
p <- p + facet_wrap(var2 ~ var1, scales = "free", ncol = 2)
输出:
自己画的,没有这样的空白:
x1x2 <- data_sub[data_sub$var1 == "x1" & data_sub$var2 == "x3", ]
ggplot(x1x2, aes(x = x, y = y)) + geom_tile(aes(fill = resp))
我认为问题在于在 geom_tile()
调用中定义某种动态 height
和 width
美学,但我不是确定如何执行此操作。似乎单个图 block 图将使用 diff((unique(x))
之类的东西来得出适当的高度,但我不确定如何为每个方面级别执行此操作 -是在我的数据框中创建此类列的唯一方法吗?
数据:
dput(data_sub)
structure(list(x = c(-3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, -3, -2.33333333333333, -1.66666666666667,
-1, -0.333333333333333, 0.333333333333333, 1, 1.66666666666667,
2.33333333333333, 3, 0, 0.111111111111111, 0.222222222222222,
0.333333333333333, 0.444444444444444, 0.555555555555556, 0.666666666666667,
0.777777777777778, 0.888888888888889, 1, 0, 0.111111111111111,
0.222222222222222, 0.333333333333333, 0.444444444444444, 0.555555555555556,
0.666666666666667, 0.777777777777778, 0.888888888888889, 1, 0,
0.111111111111111, 0.222222222222222, 0.333333333333333, 0.444444444444444,
0.555555555555556, 0.666666666666667, 0.777777777777778, 0.888888888888889,
1, 0, 0.111111111111111, 0.222222222222222, 0.333333333333333,
0.444444444444444, 0.555555555555556, 0.666666666666667, 0.777777777777778,
0.888888888888889, 1, 0, 0.111111111111111, 0.222222222222222,
0.333333333333333, 0.444444444444444, 0.555555555555556, 0.666666666666667,
0.777777777777778, 0.888888888888889, 1, 0, 0.111111111111111,
0.222222222222222, 0.333333333333333, 0.444444444444444, 0.555555555555556,
0.666666666666667, 0.777777777777778, 0.888888888888889, 1, 0,
0.111111111111111, 0.222222222222222, 0.333333333333333, 0.444444444444444,
0.555555555555556, 0.666666666666667, 0.777777777777778, 0.888888888888889,
1, 0, 0.111111111111111, 0.222222222222222, 0.333333333333333,
0.444444444444444, 0.555555555555556, 0.666666666666667, 0.777777777777778,
0.888888888888889, 1, 0, 0.111111111111111, 0.222222222222222,
0.333333333333333, 0.444444444444444, 0.555555555555556, 0.666666666666667,
0.777777777777778, 0.888888888888889, 1, 0, 0.111111111111111,
0.222222222222222, 0.333333333333333, 0.444444444444444, 0.555555555555556,
0.666666666666667, 0.777777777777778, 0.888888888888889, 1, 0,
0.111111111111111, 0.222222222222222, 0.333333333333333, 0.444444444444444,
0.555555555555556, 0.666666666666667, 0.777777777777778, 0.888888888888889,
1, 0, 0.111111111111111, 0.222222222222222, 0.333333333333333,
0.444444444444444, 0.555555555555556, 0.666666666666667, 0.777777777777778,
0.888888888888889, 1, 0, 0.111111111111111, 0.222222222222222,
0.333333333333333, 0.444444444444444, 0.555555555555556, 0.666666666666667,
0.777777777777778, 0.888888888888889, 1, 0, 0.111111111111111,
0.222222222222222, 0.333333333333333, 0.444444444444444, 0.555555555555556,
0.666666666666667, 0.777777777777778, 0.888888888888889, 1, 0,
0.111111111111111, 0.222222222222222, 0.333333333333333, 0.444444444444444,
0.555555555555556, 0.666666666666667, 0.777777777777778, 0.888888888888889,
1, 0, 0.111111111111111, 0.222222222222222, 0.333333333333333,
0.444444444444444, 0.555555555555556, 0.666666666666667, 0.777777777777778,
0.888888888888889, 1, 0, 0.111111111111111, 0.222222222222222,
0.333333333333333, 0.444444444444444, 0.555555555555556, 0.666666666666667,
0.777777777777778, 0.888888888888889, 1, 0, 0.111111111111111,
0.222222222222222, 0.333333333333333, 0.444444444444444, 0.555555555555556,
0.666666666666667, 0.777777777777778, 0.888888888888889, 1, 0,
0.111111111111111, 0.222222222222222, 0.333333333333333, 0.444444444444444,
0.555555555555556, 0.666666666666667, 0.777777777777778, 0.888888888888889,
1, 0, 0.111111111111111, 0.222222222222222, 0.333333333333333,
0.444444444444444, 0.555555555555556, 0.666666666666667, 0.777777777777778,
0.888888888888889, 1), y = c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6.66666666666667,
6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667,
6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667,
6.66666666666667, 8.33333333333333, 8.33333333333333, 8.33333333333333,
8.33333333333333, 8.33333333333333, 8.33333333333333, 8.33333333333333,
8.33333333333333, 8.33333333333333, 8.33333333333333, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 11.6666666666667, 11.6666666666667,
11.6666666666667, 11.6666666666667, 11.6666666666667, 11.6666666666667,
11.6666666666667, 11.6666666666667, 11.6666666666667, 11.6666666666667,
13.3333333333333, 13.3333333333333, 13.3333333333333, 13.3333333333333,
13.3333333333333, 13.3333333333333, 13.3333333333333, 13.3333333333333,
13.3333333333333, 13.3333333333333, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 16.6666666666667, 16.6666666666667, 16.6666666666667,
16.6666666666667, 16.6666666666667, 16.6666666666667, 16.6666666666667,
16.6666666666667, 16.6666666666667, 16.6666666666667, 18.3333333333333,
18.3333333333333, 18.3333333333333, 18.3333333333333, 18.3333333333333,
18.3333333333333, 18.3333333333333, 18.3333333333333, 18.3333333333333,
18.3333333333333, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.777777777777778, 0.777777777777778,
0.777777777777778, 0.777777777777778, 0.777777777777778, 0.777777777777778,
0.777777777777778, 0.777777777777778, 0.777777777777778, 0.777777777777778,
1.55555555555556, 1.55555555555556, 1.55555555555556, 1.55555555555556,
1.55555555555556, 1.55555555555556, 1.55555555555556, 1.55555555555556,
1.55555555555556, 1.55555555555556, 2.33333333333333, 2.33333333333333,
2.33333333333333, 2.33333333333333, 2.33333333333333, 2.33333333333333,
2.33333333333333, 2.33333333333333, 2.33333333333333, 2.33333333333333,
3.11111111111111, 3.11111111111111, 3.11111111111111, 3.11111111111111,
3.11111111111111, 3.11111111111111, 3.11111111111111, 3.11111111111111,
3.11111111111111, 3.11111111111111, 3.88888888888889, 3.88888888888889,
3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889,
3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889,
4.66666666666667, 4.66666666666667, 4.66666666666667, 4.66666666666667,
4.66666666666667, 4.66666666666667, 4.66666666666667, 4.66666666666667,
4.66666666666667, 4.66666666666667, 5.44444444444444, 5.44444444444444,
5.44444444444444, 5.44444444444444, 5.44444444444444, 5.44444444444444,
5.44444444444444, 5.44444444444444, 5.44444444444444, 5.44444444444444,
6.22222222222222, 6.22222222222222, 6.22222222222222, 6.22222222222222,
6.22222222222222, 6.22222222222222, 6.22222222222222, 6.22222222222222,
6.22222222222222, 6.22222222222222, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6.66666666666667, 6.66666666666667,
6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667,
6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667,
8.33333333333333, 8.33333333333333, 8.33333333333333, 8.33333333333333,
8.33333333333333, 8.33333333333333, 8.33333333333333, 8.33333333333333,
8.33333333333333, 8.33333333333333, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 11.6666666666667, 11.6666666666667, 11.6666666666667,
11.6666666666667, 11.6666666666667, 11.6666666666667, 11.6666666666667,
11.6666666666667, 11.6666666666667, 11.6666666666667, 13.3333333333333,
13.3333333333333, 13.3333333333333, 13.3333333333333, 13.3333333333333,
13.3333333333333, 13.3333333333333, 13.3333333333333, 13.3333333333333,
13.3333333333333, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16.6666666666667,
16.6666666666667, 16.6666666666667, 16.6666666666667, 16.6666666666667,
16.6666666666667, 16.6666666666667, 16.6666666666667, 16.6666666666667,
16.6666666666667, 18.3333333333333, 18.3333333333333, 18.3333333333333,
18.3333333333333, 18.3333333333333, 18.3333333333333, 18.3333333333333,
18.3333333333333, 18.3333333333333, 18.3333333333333, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0.777777777777778, 0.777777777777778, 0.777777777777778, 0.777777777777778,
0.777777777777778, 0.777777777777778, 0.777777777777778, 0.777777777777778,
0.777777777777778, 0.777777777777778, 1.55555555555556, 1.55555555555556,
1.55555555555556, 1.55555555555556, 1.55555555555556, 1.55555555555556,
1.55555555555556, 1.55555555555556, 1.55555555555556, 1.55555555555556,
2.33333333333333, 2.33333333333333, 2.33333333333333, 2.33333333333333,
2.33333333333333, 2.33333333333333, 2.33333333333333, 2.33333333333333,
2.33333333333333, 2.33333333333333, 3.11111111111111, 3.11111111111111,
3.11111111111111, 3.11111111111111, 3.11111111111111, 3.11111111111111,
3.11111111111111, 3.11111111111111, 3.11111111111111, 3.11111111111111,
3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889,
3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889,
3.88888888888889, 3.88888888888889, 4.66666666666667, 4.66666666666667,
4.66666666666667, 4.66666666666667, 4.66666666666667, 4.66666666666667,
4.66666666666667, 4.66666666666667, 4.66666666666667, 4.66666666666667,
5.44444444444444, 5.44444444444444, 5.44444444444444, 5.44444444444444,
5.44444444444444, 5.44444444444444, 5.44444444444444, 5.44444444444444,
5.44444444444444, 5.44444444444444, 6.22222222222222, 6.22222222222222,
6.22222222222222, 6.22222222222222, 6.22222222222222, 6.22222222222222,
6.22222222222222, 6.22222222222222, 6.22222222222222, 6.22222222222222,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7), var1 = c("x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1",
"x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x1", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2",
"x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2", "x2"
), var2 = c("x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3", "x3",
"x3", "x3", "x3", "x3", "x3", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4", "x4",
"x4", "x4", "x4", "x4", "x4", "x4"), resp = c(49.855790574209,
51.1750882867235, 52.494385999238, 53.8136837117525, 55.132981424267,
56.4522791367815, 57.771576849296, 59.0908745618105, 60.410172274325,
61.7294699868395, 56.5060300788685, 57.825327791383, 59.1446255038975,
60.463923216412, 61.7832209289265, 63.102518641441, 64.4218163539555,
65.74111406647, 67.0604117789845, 68.379709491499, 63.1562695835279,
64.4755672960424, 65.7948650085569, 67.1141627210714, 68.4334604335859,
69.7527581461004, 71.0720558586149, 72.3913535711294, 73.7106512836439,
75.0299489961584, 69.8065090881873, 71.1258068007018, 72.4451045132163,
73.7644022257308, 75.0836999382454, 76.4029976507599, 77.7222953632744,
79.0415930757889, 80.3608907883034, 81.6801885008178, 76.4567485928468,
77.7760463053613, 79.0953440178758, 80.4146417303903, 81.7339394429048,
83.0532371554193, 84.3725348679338, 85.6918325804483, 87.0111302929628,
88.3304280054773, 83.1069880975062, 84.4262858100207, 85.7455835225352,
87.0648812350497, 88.3841789475642, 89.7034766600787, 91.0227743725932,
92.3420720851077, 93.6613697976222, 94.9806675101367, 89.7572276021656,
91.0765253146801, 92.3958230271947, 93.7151207397092, 95.0344184522237,
96.3537161647382, 97.6730138772527, 98.9923115897672, 100.311609302282,
101.630907014796, 96.4074671068251, 97.7267648193396, 99.0460625318541,
100.365360244369, 101.684657956883, 103.003955669398, 104.323253381912,
105.642551094427, 106.961848806941, 108.281146519456, 103.057706611485,
104.377004323999, 105.696302036514, 107.015599749028, 108.334897461543,
109.654195174057, 110.973492886572, 112.292790599086, 113.612088311601,
114.931386024115, 109.707946116144, 111.027243828658, 112.346541541173,
113.665839253687, 114.985136966202, 116.304434678716, 117.623732391231,
118.943030103745, 120.26232781626, 121.581625528774, 44.8527240775983,
46.1720217901128, 47.4913195026273, 48.8106172151418, 50.1299149276563,
51.4492126401708, 52.7685103526853, 54.0878080651998, 55.4071057777143,
56.7264034902288, 48.7344239681344, 50.0537216806489, 51.3730193931634,
52.6923171056779, 54.0116148181924, 55.3309125307069, 56.6502102432214,
57.9695079557359, 59.2888056682504, 60.6081033807649, 52.6161238586705,
53.935421571185, 55.2547192836995, 56.574016996214, 57.8933147087285,
59.212612421243, 60.5319101337575, 61.851207846272, 63.1705055587865,
64.489803271301, 56.4978237492065, 57.817121461721, 59.1364191742355,
60.45571688675, 61.7750145992646, 63.094312311779, 64.4136100242935,
65.732907736808, 67.0522054493226, 68.3715031618371, 60.3795236397426,
61.6988213522571, 63.0181190647716, 64.3374167772861, 65.6567144898006,
66.9760122023151, 68.2953099148296, 69.6146076273441, 70.9339053398586,
72.2532030523731, 64.2612235302787, 65.5805212427932, 66.8998189553077,
68.2191166678222, 69.5384143803367, 70.8577120928512, 72.1770098053657,
73.4963075178802, 74.8156052303947, 76.1349029429092, 68.1429234208147,
69.4622211333293, 70.7815188458437, 72.1008165583582, 73.4201142708727,
74.7394119833872, 76.0587096959017, 77.3780074084163, 78.6973051209308,
80.0166028334453, 72.0246233113508, 73.3439210238653, 74.6632187363798,
75.9825164488943, 77.3018141614088, 78.6211118739233, 79.9404095864378,
81.2597072989523, 82.5790050114668, 83.8983027239813, 75.9063232018869,
77.2256209144014, 78.5449186269159, 79.8642163394304, 81.1835140519449,
82.5028117644594, 83.8221094769739, 85.1414071894884, 86.4607049020029,
87.7800026145174, 79.7880230924229, 81.1073208049374, 82.4266185174519,
83.7459162299664, 85.065213942481, 86.3845116549954, 87.7038093675099,
89.0231070800245, 90.342404792539, 91.6617025050535, 55.0389923581682,
55.076209045692, 55.1878591082632, 55.373942545882, 55.6344593585483,
55.9694095462621, 56.3787931090235, 56.8626100468323, 57.4208603596887,
58.0535440475926, 61.6892318628276, 61.7264485503514, 61.8380986129227,
62.0241820505415, 62.2846988632078, 62.6196490509216, 63.0290326136829,
63.5128495514918, 64.0710998643481, 64.703783552252, 68.3394713674871,
68.3766880550108, 68.4883381175821, 68.6744215552009, 68.9349383678672,
69.269888555581, 69.6792721183423, 70.1630890561512, 70.7213393690076,
71.3540230569114, 74.9897108721465, 75.0269275596703, 75.1385776222415,
75.3246610598603, 75.5851778725266, 75.9201280602404, 76.3295116230018,
76.8133285608106, 77.371578873667, 78.0042625615709, 81.639950376806,
81.6771670643297, 81.788817126901, 81.9749005645198, 82.2354173771861,
82.5703675648999, 82.9797511276612, 83.4635680654701, 84.0218183783264,
84.6545020662303, 88.2901898814654, 88.3274065689891, 88.4390566315604,
88.6251400691792, 88.8856568818455, 89.2206070695593, 89.6299906323207,
90.1138075701295, 90.6720578829859, 91.3047415708897, 94.9404293861248,
94.9776460736486, 95.0892961362198, 95.2753795738386, 95.5358963865049,
95.8708465742187, 96.2802301369801, 96.7640470747889, 97.3222973876453,
97.9549810755492, 101.590668890784, 101.627885578308, 101.739535640879,
101.925619078498, 102.186135891164, 102.521086078878, 102.93046964164,
103.414286579448, 103.972536892305, 104.605220580209, 108.240908395444,
108.278125082967, 108.389775145539, 108.575858583158, 108.836375395824,
109.171325583538, 109.580709146299, 110.064526084108, 110.622776396964,
111.255460084868, 114.891147900103, 114.928364587627, 115.040014650198,
115.226098087817, 115.486614900483, 115.821565088197, 116.230948650958,
116.714765588767, 117.273015901624, 117.905699589528, 50.0359258615575,
50.0731425490813, 50.1847926116525, 50.3708760492713, 50.6313928619376,
50.9663430496514, 51.3757266124128, 51.8595435502216, 52.417793863078,
53.0504775509819, 53.9176257520936, 53.9548424396173, 54.0664925021886,
54.2525759398074, 54.5130927524737, 54.8480429401875, 55.2574265029488,
55.7412434407577, 56.2994937536141, 56.9321774415179, 57.7993256426296,
57.8365423301534, 57.9481923927247, 58.1342758303435, 58.3947926430098,
58.7297428307236, 59.1391263934849, 59.6229433312938, 60.1811936441501,
60.813877332054, 61.6810255331657, 61.7182422206895, 61.8298922832607,
62.0159757208795, 62.2764925335458, 62.6114427212596, 63.020826284021,
63.5046432218298, 64.0628935346862, 64.6955772225901, 65.5627254237018,
65.5999421112255, 65.7115921737968, 65.8976756114156, 66.1581924240819,
66.4931426117957, 66.9025261745571, 67.3863431123659, 67.9445934252223,
68.5772771131261, 69.4444253142378, 69.4816420017616, 69.5932920643329,
69.7793755019516, 70.039892314618, 70.3748425023318, 70.7842260650931,
71.268043002902, 71.8262933157583, 72.4589770036622, 73.3261252047739,
73.3633418922977, 73.4749919548689, 73.6610753924877, 73.921592205154,
74.2565423928679, 74.6659259556292, 75.149742893438, 75.7079932062944,
76.3406768941983, 77.20782509531, 77.2450417828337, 77.356691845405,
77.5427752830238, 77.8032920956901, 78.1382422834039, 78.5476258461653,
79.0314427839741, 79.5896930968305, 80.2223767847343, 81.089524985846,
81.1267416733698, 81.2383917359411, 81.4244751735599, 81.6849919862262,
82.01994217394, 82.4293257367013, 82.9131426745102, 83.4713929873665,
84.1040766752704, 84.9712248763821, 85.0084415639059, 85.1200916264771,
85.3061750640959, 85.5666918767622, 85.9016420644761, 86.3110256272374,
86.7948425650462, 87.3530928779026, 87.9857765658065)), .Names = c("x",
"y", "var1", "var2", "resp"), row.names = 101:500, class = "data.frame")
最佳答案
我遇到了两个问题:
1)我的真实数据集是通过fit <- lm(x ~ y)
生成的, 然后通过 expand.grid
创建一个新的输入数据集,然后使用 predict(fit, newdata)
创建我的绘图数据.奇怪的是,如果我不舍入 x
和 y
点,我无法生成绘图(用于创建绘图数据的完整代码如下)。
2) 绘制一个 geom_tile
时plot,瓷砖的高度/宽度设置为填充空间。在创建多面图集时,似乎 height
和 width
geom_tile()
的参数默认为其他东西。我会说它们默认为最小范围,但实际上没有图填满整个小平面窗口的宽度或高度……所以不是那样。
对于上述示例无法重现,我们深表歉意。我没想到 dput()
不会创建完全相同的数据集,并且仅粘贴其输出比让某人运行下面的所有代码要简单得多。
生成数据集的完整代码:
set.seed(42)
x1 <- rnorm(20)
x2 <- runif(20)
x3 <- rpois(20,10)
x4 <- rexp(20)
y <- 10 + 2*x1 + 3*x2^2 + 4*x3 +5*x4 + rnorm(20, sd=0.1)
dat <- data.frame(x1, x2, x3, x4, y)
# vector of variable names for easy data.frame column naming later
var_names <- c("x1", "x2", "x3", "x4")
# possible combinations of four variables
combis <- combn(1:4, 2)
combis <- rbind(combis, combis[, 6:1])
# steps to generate for the contour using `rep(min, max, length.out = n)`
n <- 100
#fit the model
fit <- lm(y~x1+I(x2^2)+x3+x4, data=dat)
# range values for when variable is featured on an axis
mins_maxs <- data.frame(x1 = c(-3, 3),
x2 = c(0, 1),
x3 = c(5, 20),
x4 = c(0, 7))
# values to hold for plots in which variables are not on an axis
holds <- c(0, 0.5, 10, 5)
sim_data <- list()
sim_data <- lapply(seq_len(ncol(combis)), function (i) {
sim_data[[i]] <- expand.grid(seq(mins_maxs[1, combis[1, i]],
mins_maxs[2, combis[1, i]], length.out = n),
seq(mins_maxs[1, combis[2, i]],
mins_maxs[2, combis[2, i]], length.out = n),
holds[combis[3, i]],
holds[combis[4, i]])
} )
# we create a new data frame for the data set we want to plot
# for each contour of interest, we want the first two columns, as the second two
# were only created for the sake of feeding into our fit lm
# we'll also create a vector for facetting using paste()
plot_data <- list()
plot_data <- lapply(1:ncol(combis), function(i) {
plot_data[[i]] <- sim_data[[i]][, 1:2]
plot_data[[i]]$var1 <- rep(var_names[combis[1, i]],
nrow(plot_data[[i]]))
plot_data[[i]]$var2 <- rep(var_names[combis[2, i]],
nrow(plot_data[[i]]))
return(plot_data[[i]])
} )
# now we rename the columns of plot_data
plot_data <- lapply(1:length(plot_data), function(i) {
names(plot_data[[i]]) <- c("x", "y", "var1", "var2")
return(plot_data[[i]])
} )
# similarly, we need to re-name the sim_data columns so we can rbind them
# and predict new values using our fit lm
sim_data <- lapply(1:length(sim_data), function(i) {
names(sim_data[[i]]) <- var_names[combis[, i]]
return(sim_data[[i]])
} )
# collapse the separate lists into one data.frame
plot_data <- do.call(rbind, plot_data)
sim_data <- do.call(rbind, sim_data)
# create a vector of predictions using sim_data
plot_data$resp <- predict(fit, sim_data)
此时,如果有人尝试使用 plot_data
进行绘图,我们得到这个:
library(ggplot2)
p <- ggplot(plot_data, aes(x = x, y = y, z = resp))
p <- p + geom_tile(aes(fill = resp))
p <- p + facet_wrap(var2 ~ var1, scales = "free", ncol = 3) + theme_bw()
如果我们四舍五入数据,我们会得到其他东西:
plot_data_round <- plot_data
plot_data_round[, c("x", "y")] <- round(plot_data_round[, c("x", "y")], 5)
# same plot call as above
p <- ggplot(plot_data_round, aes(x = x, y = y, z = resp))
p <- p + geom_tile(aes(fill = resp))
p <- p + facet_wrap(var2 ~ var1, scales = "free", ncol = 3) + theme_bw()
如果我们采用未舍入的数据并添加向量来存储高度和宽度,我们将回到一个空白的多面图,就像单独的未舍入数据一样。
plot_data_hw <- plot_data
hw <- ddply(plot_data, .(var1, var2), summarize,
height = (max(y) - min(y))/n, width = (max(x) - min(x))/n)
plot_data_hw <- merge(plot_data_hw, hw, by = c("var1", "var2"), all.x = T)
# verify using same plot call and plot_data_hw
如果我们结合舍入和 height
和 width
每个方面交互的值,我们得到了期望的结果(将 height
/width
参数添加到 geom_tile()
):
plot_data_hw_round <- merge(plot_data_round, hw, by = c("var1", "var2"), all.x = T)
p <- ggplot(plot_data_hw_round, aes(x = x, y = y, z = resp))
p <- p + geom_tile(aes(fill = resp, height = height, width = width))
p <- p + facet_wrap(var2 ~ var1, scales = "free", ncol = 3) + theme_bw()
原来如此。我将提交一份关于舍入问题的错误报告,因为这对我来说似乎很奇怪。也许除此之外还有其他事情正在发生,但如果是,但由于浮点精度或诸如此类的原因,Hadley 可能仍然感兴趣。
关于r - 组合 geom_tile() 和 facet_grid/facet_wrap 并删除图 block 之间的空间 (ggplot2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18157975/
我想填充 3D 等高线图 (contour3(X,Y,Z)),就像 2D 等高线填充图 (contourf(X,Y,Z))。但我无法弄清楚如何实现这一目标。 contour3 和 surf 的组合不是
我有一个 c3.js 折线图,表示 2 个值的演变。我需要折线图的工具提示是饼图(工具提示 = 另一个 c3.js 图形)。 这是我成功的: http://jsfiddle.net/owhxgaqm/
我有具有结构的 Pandas 数据框: A B 0 1 1 1 2 1 2 3 4 3 3 7 4 6 8 如何生成 Seaborn Violin 图,每列作为其自己的单独
我正在使用 D3DXSPRITE 方法将我的 map 图 block 绘制到屏幕上,我刚刚添加了一个缩放功能,当您按住向上箭头时会放大,但注意到您现在可以看到图 block 之间的间隙,这是一些屏幕截
1、系统环境如下图: 2、为该系统添加一块新的虚拟硬盘,添加后需重启虚拟机,否则系统不识别;如下图,/dev/sdc 是新添加的硬盘; 3、fdisk /dev/sdc为新硬盘创建分区:
1、nagios简介 nagios是一款开源的电脑系统和网络监视工具,能有效监控windows、linux和unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发
越来越多人开始习惯用手机上网,浏览网页、查看邮件···移动化已经成为互联网发展必然趋势,包括facebook在内的很多互联网公司都将移动广告作为下一个淘金地
1.图片处理 1.圆角图片 复制代码 代码如下: /** * 转换成圆角 * &n
Microsoft SQL Server Management Studio是SQL SERVER的客户端工具,相信大家都知道。我不知道大伙使用导入数据的情况怎么样,反正我最近是遇到过。主要是因为没
debian6系统: 首先先安装mysql吧: 打开终端(root)用户登入 apt-get purge mysql-server-5.5 安装完成后: 默认情况下Mysql只允许本地登录
fedora16英文环境下支持中文输入法的方法 fedora16英文环境下支持FCITX的中文输入法: $ im-chooser 就会出现选择界面,选择第二个就行了。
Net预编译命令 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -? 显示说明 我们需要选择的命令为&n
有的时候电脑出现一些故障有的时候通过将其修改bios设置的方法来解决故障,那么在bios上设置能不能将电脑恢复出厂设置呢?其实也是可以的。方法也很简单的,只要会进入电脑的bios懂的上面英文的意思就
笔者曾介绍过Deepin 将对龙芯进行全面支持,打造最优美龙芯电脑桌面。现在Deepin团队移植工作取得了突破性的成果,Deepin桌面已经在龙芯3A和龙芯3B电脑上成功运行起来了。 以下为龙芯3
在安装一些软件之后,我们的电脑总是会发生一点小变化,不是桌面上多了几个网址图标,就是IE浏览器的默认主页被篡改成乱七八糟的网址。最可气的是,在IE设置中将默认主页改回来后,下次启动Win7后又变了回
“注册表编辑器怎么打开”虽说不是很难的问题,但是对于对电脑常识不是很擅长的网民来说,当电脑出现问题或需要更改设置时,着实还是件头疼的问题。因为需要打开注册表进行操作解决。那么如何打开注册表编辑器呢?
这篇文章重点介绍10个重要的WordPress安全插件和技巧,用来保护WordPress网站或者博客。 1. WP Security 人工帮助你修复被黑客入侵的网站,只要按照他们网站上的联系电话
其实运用object和javascript调用外部文件,也能实现不同栏目调用不同友情链接,即相当于调用不同栏目友情链接文件, {dede:field.typeid/}来获取当前栏目的ID。
我有一个复值矩阵。 如果我发出命令: plot(myMatrix) 然后它在图形设备上显示一种散点图,X 轴标记为 Re(myMatrix),Y 轴标记为 Im(myMatrix)。这显示了我正在寻找
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我是一名优秀的程序员,十分优秀!