Error in ggplot(df, aes(x = x, y = y)) : could not find function “ggplot“
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error in ggplot(df, aes(x = x, y = y)) : could not find function “ggplot“相关的知识,希望对你有一定的参考价值。
Error in ggplot(df, aes(x = x, y = y)) : could not find function "ggplot"
目录
Error in ggplot(df, aes(x = x, y = y)) : could not find function "ggplot"
问题:
没有安装ggplot2包怎么能使用其中的函数那:
#create data frame
df <- data.frame(x=c(1, 2, 4, 5, 7, 8, 9, 10),
y=c(12, 17, 27, 39, 50, 57, 66, 80))
#create scatterplot of x vs. y
ggplot(df, aes(x=x, y=y)) +
geom_point()
解决:
#导入library(ggplot2)
#install.packages('ggplot2')
#导入library(ggplot2)
#install ggplot2 and all dependencies
install.packages("ggplot2", dependencies=TRUE)
#删除之后重新安装;
#remove ggplot2
remove.packages("ggplot2")
#install ggplot2
install.packages("ggplot2")
#load ggplot2
library(ggplot2)
library(ggplot2)
#create scatterplot of x vs. y
ggplot(df, aes(x=x, y=y)) +
geom_point()
如果前面的修复都不起作用,可能需要简单地验证在R中运行的代码块是否正确,是否是在当前环境中安装并加载了ggplot2包。
完整错误:
#create data frame df <- data.frame(x=c(1, 2, 4, 5, 7, 8, 9, 10), y=c(12, 17, 27, 39, 50, 57, 66, 80)) #create scatterplot of x vs. y ggplot(df, aes(x=x, y=y)) + geom_point() Error in ggplot(df, aes(x = x, y = y)) : could not find function "ggplot"
以上是关于Error in ggplot(df, aes(x = x, y = y)) : could not find function “ggplot“的主要内容,如果未能解决你的问题,请参考以下文章