1
次は(私が右のプロットを取得する)うまく機能:しかしggplot2:非数値引数二項演算子に
library(ggplot2)
myfunc <- function(x)
{
n = length(x)
return(sqrt(x)+rnorm(n,0,0.05))
}
myplot1 <- function(df,x,color)
{
df$y <- myfunc(df[[x]])
p <- geom_point(data=df,
aes_string(x=x,y="y"),
colour=color)
return(p)
}
myplot2 <- function(df,x,color)
{
df$y <- myfunc(df[[x]])
p <- geom_smooth(data=df,
aes_string(x=x,y="y"),
colour=color,
method="lm")
return(p)
}
n <- 100
df <- data.frame(X1 = runif(n,0,1),
X2 = rnorm(n,0.5,0.01))
p <- ggplot()
p <- p + myplot1(df,"X1","black") + myplot2(df,"X1","black")
p <- p + myplot1(df,"X2","blue") + myplot2(df,"X2","blue")
p + theme_minimal()
、私は
myplot <- function(df,x,color)
{
df$y <- myfunc(df[[x]])
p <- geom_point(data=df,
aes_string(x=x,y="y"),
colour=color) +
geom_smooth(data=df,
aes_string(x=x,y="y"),
colour=color,
method="lm")
return(p)
}
のように2つの関数myplot1とmyplot2をマージする場合
ので、私は
を取得p <- ggplot()
p <- p + myplot(df,"X1","black")
p <- p + myplot(df,"X2","blue")
p + theme_minimal()
を使用
エラー[...]バイナリ演算子の非数値引数
どうすればこの問題を解決できますか?
ありがとう!それは機能し、私はそのような解決策を考え出すことはできませんでした。 – user11634