ggplot2 翻转的 y 轴条未显示正确设置的限制
ggplot2 flipped y-axis bars not showing with correctly set limits
我试图在 ggplot2
中绘制分类 x 轴变量的连续 y 轴值(然后翻转它们),但我的 y 轴值没有显示。
这是我的数据集:
AIC.means AIC.lci AIC.uci
Sparse Dual Stream -4632.137 -4655.353 -4608.922
Heterogeneous Dual Stream A -4627.653 -4650.866 -4604.439
Heterogeneous Dual Stream B -4622.063 -4645.194 -4598.932
Dense Dual Stream -4616.507 -4639.633 -4593.381
Radical Storage -4615.934 -4639.052 -4592.817
Radical Sparse Comp. -4601.292 -4624.428 -4578.156
Radical Heterogeneous Comp. B -4600.650 -4623.785 -4577.515
Radical Dense Comp. -4589.490 -4612.632 -4566.348
Radical Heterogeneous Comp. A -4587.993 -4611.141 -4564.845
这是剧情的代码,也是我制作的剧情。
ggplot(AIC.plotdata, aes(x=row.names(AIC.plotdata), y=AIC.means)) +
geom_bar(aes(), stat="identity") +
scale_y_continuous(limits = c(-4700, -4500)) +
coord_flip()
我将 y 轴限制设置为低于最小值和高于最大值,如下所示。因此,缺少 y 轴标签不能是因为它们超出了轴范围。
summary(AIC.plotdata$AIC.means)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-4632 -4622 -4616 -4610 -4601 -4588
这就是我试图在 ggplot2
中获得的内容,但使用 lattice
获得(AIC 值按排序顺序出现,我还需要为 ggplot 弄清楚)。
非常感谢你的帮助!
使用 geom_segement
并在 ggplot
调用中移动数据怎么样?看到这个问题类似 ggplot2: Setting geom_bar baseline to 1 instead of zero:
ggplot(df) +
geom_segment(aes(x=rownames, xend=rownames, y=-4700, yend=AIC.means), size = 10) +
scale_y_continuous(limits = c(-4700, -4500)) +
coord_flip()
数据:
df <- structure(list(rownames = c("Sparse Dual Stream", "Heterogeneous Dual Stream A",
"Heterogeneous Dual Stream B", "Dense Dual Stream", "Radical Storage",
"Radical Sparse Comp.", "Radical Heterogeneous Comp. B", "Radical Dense Comp.",
"Radical Heterogeneous Comp. A"), AIC.means = c(-4632.137, -4627.653,
-4622.063, -4616.507, -4615.934, -4601.292, -4600.65, -4589.49,
-4587.993), AIC.lci = c(-4655.353, -4650.866, -4645.194, -4639.633,
-4639.052, -4624.428, -4623.785, -4612.632, -4611.141), AIC.uci = c(-4608.922,
-4604.439, -4598.932, -4593.381, -4592.817, -4578.156, -4577.515,
-4566.348, -4564.845)), .Names = c("rownames", "AIC.means", "AIC.lci",
"AIC.uci"), row.names = c(NA, -9L), class = "data.frame")
我试图在 ggplot2
中绘制分类 x 轴变量的连续 y 轴值(然后翻转它们),但我的 y 轴值没有显示。
这是我的数据集:
AIC.means AIC.lci AIC.uci
Sparse Dual Stream -4632.137 -4655.353 -4608.922
Heterogeneous Dual Stream A -4627.653 -4650.866 -4604.439
Heterogeneous Dual Stream B -4622.063 -4645.194 -4598.932
Dense Dual Stream -4616.507 -4639.633 -4593.381
Radical Storage -4615.934 -4639.052 -4592.817
Radical Sparse Comp. -4601.292 -4624.428 -4578.156
Radical Heterogeneous Comp. B -4600.650 -4623.785 -4577.515
Radical Dense Comp. -4589.490 -4612.632 -4566.348
Radical Heterogeneous Comp. A -4587.993 -4611.141 -4564.845
这是剧情的代码,也是我制作的剧情。
ggplot(AIC.plotdata, aes(x=row.names(AIC.plotdata), y=AIC.means)) +
geom_bar(aes(), stat="identity") +
scale_y_continuous(limits = c(-4700, -4500)) +
coord_flip()
我将 y 轴限制设置为低于最小值和高于最大值,如下所示。因此,缺少 y 轴标签不能是因为它们超出了轴范围。
summary(AIC.plotdata$AIC.means)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-4632 -4622 -4616 -4610 -4601 -4588
这就是我试图在 ggplot2
中获得的内容,但使用 lattice
获得(AIC 值按排序顺序出现,我还需要为 ggplot 弄清楚)。
非常感谢你的帮助!
使用 geom_segement
并在 ggplot
调用中移动数据怎么样?看到这个问题类似 ggplot2: Setting geom_bar baseline to 1 instead of zero:
ggplot(df) +
geom_segment(aes(x=rownames, xend=rownames, y=-4700, yend=AIC.means), size = 10) +
scale_y_continuous(limits = c(-4700, -4500)) +
coord_flip()
数据:
df <- structure(list(rownames = c("Sparse Dual Stream", "Heterogeneous Dual Stream A",
"Heterogeneous Dual Stream B", "Dense Dual Stream", "Radical Storage",
"Radical Sparse Comp.", "Radical Heterogeneous Comp. B", "Radical Dense Comp.",
"Radical Heterogeneous Comp. A"), AIC.means = c(-4632.137, -4627.653,
-4622.063, -4616.507, -4615.934, -4601.292, -4600.65, -4589.49,
-4587.993), AIC.lci = c(-4655.353, -4650.866, -4645.194, -4639.633,
-4639.052, -4624.428, -4623.785, -4612.632, -4611.141), AIC.uci = c(-4608.922,
-4604.439, -4598.932, -4593.381, -4592.817, -4578.156, -4577.515,
-4566.348, -4564.845)), .Names = c("rownames", "AIC.means", "AIC.lci",
"AIC.uci"), row.names = c(NA, -9L), class = "data.frame")