R课程记录--第一课

R课程记录–第一课@TOC

本篇的文章结构
1 R的安装以及R studio的安装。
2 老师提供的练习网页的学习。出现的错误,以及订正的方法。

R的安装

R的安装主要步骤:

  1. 找到R的官网https://cran.r-prigect.org/.可以找到最新的版本
  2. ,也可以下载最好用的3.5.3.还可以考虑微软发行的开源R版本。

Rstudio的安装

作为R的调试版本。可以下载的地址是https://www.rstudio.com/

课程的内容

练习一

1 安装包
install.packages(‘tidyverse’)
install.packages(‘modelr’)
install.packages(‘gapminder’)
install.packages(‘ggbeeswarm’)
install.packages(‘gganimate’)
install.packages(‘ggstance’)
2 加载library
library(tidyverse)
library(modelr)
options(na.action = na.warn)
library(gapminder)
library(ggbeeswarm)
library(gganimate)
library(ggstance)

一定要检查上述的package和library是否安装正常。
3 查看“gapminder”的数据出来没
4
gapminder %>%
ggplot(aes(year, lifeExp, color = country)) +
geom_line(alpha = 1/3) +
scale_color_viridis_d(guide = F)
在这里插入图片描述

练习二

1 在上述package和library的基础上,输入代码
animate_df <- gapminder %>%
filter(continent == ‘Asia’) %>%
arrange(year, lifeExp) %>%
mutate(order = 1:n())

animate_fills <- viridis::viridis(33)
animate_fills[5] <- ‘red’
p <- animate_df %>%
ggplot(aes(lifeExp, order, fill = country)) +
geom_barh(stat = “identity”) +
labs(title=’{closest_state}’) +
scale_fill_manual(values = animate_fills, guide = F) +
scale_y_continuous(breaks=animate_df o r d e r , l a b e l s = a n i m a t e d f order, labels=animate_df order,labels=animatedfcountry, expand = c(0, 0)) +
transition_states(year, transition_length = 1, state_length = 50) +
view_follow(fixed_x = T) +
ease_aes(‘linear’)
animate(p, nframes = 60)

  • 提示报错p变量为有数值。差错发现p变量在animat_df这个数据就出现未传递的情况。

老师提供了新版的代码
animate_df <- gapminder %>%
filter(continent == ‘Asia’) %>%
arrange(year, lifeExp) %>%
mutate(order = 1:n())

animate_fills <- viridis::viridis(33)
animate_fills[5] <- ‘red’
animate_df %>%
ggplot(aes(lifeExp, order, fill = country)) +
geom_barh(stat = “identity”) +
labs(title=’{closest_state}’) +
scale_fill_manual(values = animate_fills, guide = F) +
scale_y_continuous(breaks=animate_df o r d e r , l a b e l s = a n i m a t e d f order, labels=animate_df order,labels=animatedfcountry, expand = c(0, 0)) +
transition_states(year, transition_length = 1, state_length = 50) +
view_follow(fixed_x = T) +
ease_aes(‘linear’)
补充解决的方法是加载了’devtools’的安装包,以及devtools::install_github(‘thomasp85/gganimate’) 的代码。并添加了library(ggplot2) 和library(gifski)。出现图形
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值