R中的层命令错误
我正在尝试使用以下语法在R-Studio中生成多层绘图:R中的层命令错误,r,ggplot2,data-visualization,layer,R,Ggplot2,Data Visualization,Layer,我正在尝试使用以下语法在R-Studio中生成多层绘图: ## Load packages library(foreign) library(pscl) library(ggplot2) library(latticeExtra) library(DAAG) ## Plot functions and points fun.1 <- function(x) 1-2*.01*x fun.2 <- function(x) 1-2*.05*x fun.3 <- function(x
## Load packages
library(foreign)
library(pscl)
library(ggplot2)
library(latticeExtra)
library(DAAG)
## Plot functions and points
fun.1 <- function(x) 1-2*.01*x
fun.2 <- function(x) 1-2*.05*x
fun.3 <- function(x) 1-2*.1*x
puntos <- data.frame(panelp=c(indicator11$propMean, indicator12$propMean , indicator13$propMean,
indicator14$propMean, indicator15$propMean),
panelr=c(indicator11$R, indicator12$R, indicator13$R, indicator14$R, indicator15$R),
survp=c(indicator21$propMean, indicator22$propMean , indicator23$propMean,
indicator24$propMean, indicator25$propMean),
survr=c(indicator21$R, indicator22$R, indicator23$R, indicator24$R, indicator25$R),
panelpw=c(indicator11w$propMean, indicator12w$propMean , indicator13w$propMean,
indicator14w$propMean, indicator15w$propMean),
panelrw=c(indicator11w$R, indicator12w$R, indicator13w$R, indicator14w$R, indicator15w$R),
survpw=c(indicator21w$propMean, indicator22w$propMean , indicator23w$propMean,
indicator24w$propMean, indicator25w$propMean),
survrw=c(indicator21w$R, indicator22w$R, indicator23w$R, indicator24w$R, indicator25w$R),
modelo=c(1,2,3,4,5))
as.factor(puntos$modelo)
p <- ggplot(data = data.frame(x = 0), aes(x = x))
p +
layer(stat = "function",
fun = fun.1, colour="deepskyblue2"
) +
layer(stat = "function",
fun = fun.2, colour="deepskyblue2"
) +
layer(stat = "function",
fun = fun.3, colour="deepskyblue2"
) +
geom_point(data=puntos,aes(panelp,panelr, colour=factor(modelo)),size=4) +
geom_point(data=puntos,aes(survp,survr, colour=factor(modelo)),size=4) +
scale_x_continuous(limits = c(.0, 1)) +
scale_y_continuous(limits = c(.6, 1)) +
ylab("R-indicator") +
xlab("Response rate") +
theme(plot.title = element_text(lineheight=1.1, face="bold"))+
theme(legend.position="bottom") +
ggtitle("R-indicators (unweighted model)") +
scale_color_manual(name = "Models",
values = c("chocolate3", "coral1", "darkorchid2", "khaki",
"olivedrab4"),
labels = c("Model 1", "Model 2", "Model 3", "Model 4", "Model 5"))
##加载包
图书馆(外文)
图书馆(pscl)
图书馆(GG2)
图书馆(latticeExtra)
图书馆(DAAG)
##绘图函数和点
乐趣。1您可能不应该使用layer()
,而应该使用stat\u function()
。还要注意layer
没有fun
和color
参数。使用stat\u function()而不是layer()就可以了!非常感谢。