在按照ggplot2原书代码逐步学习过程中发现,作者使用的数据集movies总是报错。
> hgram <- qplot(ratting, data = movies, binwidth =1)
Error in eval_tidy(mapping$x, data, caller_env) :
object 'movies' not found
按照代码流程,安装的包或数据集都有,从错误提示中可以看出,找不到movies数据集,于是查看了R内置的数据集和包自带的数据集。
data() #列出已载入的包中的所有数据集。
data(package = .packages(all.available = TRUE)) #列出已安装的包中的所有数据集。
没有找到名为"movies"的包,确信是数据集问题。百度搜索"ggplot2 movies",从第一个链接中找到了答案。ggplot2作者已经说了,数据集movies包含在旧版ggplot2中,为了减轻ggplot2包容量已经移除了(也仅有908 KB )。但是还可以从下面的链接中找到下载地址。
image.png
image.png
于是下载ggplot2movies_0.0.1.tar,手动安装。
方法1:
Tools > Install Packages... > Install from:(安装tar.gz) > Browse...(下载路径) > Install

方法2:
> install.packages("D:/360安全浏览器下载/ggplot2movies_0.0.1.tar.gz", repos = NULL, type = "source")
* installing *source* package 'ggplot2movies' ...
** 成功将'ggplot2movies'程序包解包并MD5和检查
** R
** data
*** moving datasets to lazyload DB
** byte-compile and prepare package for lazy loading
安装完成后,然后加载一下,大功告成,可以按照ggplot2的代码进行练习了。
library(ggplot2movies)
hgram <- qplot(rating, data = movies, binwidth =1)
hgram
previous_theme <- theme_set(theme_bw())
hgram
hgram + previous_theme
theme_set(previous_theme)


网友评论