我想添加一个散点图以覆盖到R中的ggplot直方图上。
在下面的geom_point()上给我一个错误:错误:mapping
必须由aes()
创建
您能提供指导吗?
rand_nr <- 10000
rand_max <- 1
rand_min <- 0
lambda <- 1
x_min <- 0
x_max <- 10
bin_nr <- 50
diff_x <- (x_max - x_min) / bin_nr
edge <- seq(x_min, x_max, diff_x)
x_var <- seq(x_min, x_max, 0.01) # actual x variable
rand_var <- runif(rand_nr, rand_min, rand_max)
X <- tan(rand_var * pi / 2) # F(X)=(2/pi)*atan(x)
p <- 1 / (1 + (x_var^2))
X_df <- data.frame(X, group = "x")
P_df <- data.frame(p, group = "p")
plot(rand_var) # plot the random variables
ggplot(X_df, aes(X, probability (x),fill=group, colour=group)) +
geom_histogram(aes(y=..density..), breaks=edge, alpha=0.6,
position="identity", lwd=0.2) +
ggtitle("Normalized")
上面的工作代码。无效代码如下
ggplot(X_df, aes(X, probability (x),fill=group, colour=group)) +
geom_histogram(aes(y=..density..), breaks=edge, alpha=0.6,
position="identity", lwd=0.2) +
geom_point(x_var,p,aes(x1,px1)) +
ggtitle("Normalized")
答案 0 :(得分:2)