带状图叠加条形图

我想将条形图与stripplot叠加,并在xyplot中使用面板参数表,但是它不起作用。它什么也没画,并发出许多警告,例如:

1: In order(as.numeric(x)) : NAs introduced by coercion
2: In diff(as.numeric(x[ord])) : NAs introduced by coercion

代码在这里,但是它可以使用阶乘Alternatice和Subject变量,尽管它以水平方式绘制条形图:

t2 <- data.frame(Alternative = c("FA","HF","NO","FA","NO"),AlloOthe = c(50,80,20,20),Subject = rep(c("2001","2002"),each = 3)
)
t2$Alternative <- as.character(t2$Alternative)
t2$Subject <- as.character(t2$Subject)
library(lattice)
xyplot(AlloOthe ~ Alternative | Subject,data = t2,panel = function(x,y) {
    panel.barchart(x,y)
    panel.stripplot(x,y,type = c("p","l"))
  },ylab = "Allocation to Other"
)

那么,有谁能给我看正确的代码或使它适用于正确的数据?非常感谢!

w1931079www 回答:带状图叠加条形图

我不是lattice软件包的专家,但是我可以按照以下帖子了解您的情节:Add stripplot points to bwplot (Lattice graphics in R),因此,我在面板函数定义中添加了...并替换了xyplot的{​​{1}}。

因此,基本上,它看起来像:

barchart

情节如下:

enter image description here

作为替代方案,您可以通过执行以下操作来使用# Assigning Alternative and Subject as factor t2$Alternative = as.factor(t2$Alternative) t2$Subject = as.factor(t2$Subject) library(lattice) barchart(AlloOthe ~ Alternative | Subject,data = t2,panel = function(x,y,...) { panel.barchart(x,col=adjustcolor("darkorchid",alpha=.6),...) panel.stripplot(x,col="lightseagreen",pch=16,size=3,...) },ylab = "Allocation to Other")

ggplot

情节如下:

enter image description here

希望它对您有帮助!

本文链接:https://www.f2er.com/3126916.html

大家都在问