我正在爲ggplot添加一個點,我如何將x和y座標作爲變量?我想這個代碼,但它不工作如何在將點添加到ggplot時將x和y座標作爲變量?
func <- function(data){
meanx <- mean(data[,1])
meany <- mean(data[,2])
p <- ggplot(data, aes(x = data[,1], y = data[,2]))
p +
geom_point(size = 5, shape = 19, color = "#00FF00",
aes(x = meanx, y = meany))
}
func(iris)
我有以下錯誤:
Error in eval(expr, envir, enclos) : object 'meanx' not found
誰能幫助我嗎?
看看'aes_string' – Justin