实验1 时间趋势可视化之柱状图

一. 实验目的和要求

1. 了解时间趋势可视化知识,学习与掌握柱状图的生成方法;

2. 学习并掌握R+Illustrator可视化绘图模式。

二. 实验过程

1. 根据《鲜活的数据》第4章4.2.1提供的数据,在R中绘制柱状图,并存为PDF文件;

2. 将上一步所得的PDF文件,导入Illustrator,参考教材图4-5样图,对其修改与修饰,并添上自己的署名。

三. 实验代码参考

// 4.2.1 柱形
hotdogs<-read.csv("http://datasets.flowingdata.com/hot-dog-contest-winners.csv", sep=",", header=TRUE)
hotdogs<-read.csv("hot-dog-contest-winners.csv", sep=",", header=TRUE)
hotdogs$Dogs.eaten
barplot(hotdogs$Dogs.eaten)
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year)
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col = "red", border = NA, xlab="Year", ylab="Hot dogs and buns (HDB) eaten")
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col = "#821122", border = NA, xlab="Year", ylab="Hot dogs and buns (HDB) eaten")
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col = "#cccccc", border = NA, xlab="Year", ylab="Hot dogs and buns (HDB) eaten")

fill_colors<-c()
for(i in 1:length(hotdogs$Country)){
if(hotdogs$Country[i] == "United States")
{
fill_colors <- c(fill_colors, "#821122")
}
else
{
fill_colors <- c(fill_colors, "#cccccc")
}
}
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col = fill_colors, border = NA, xlab="Year", ylab="Hot dogs and buns (HDB) eaten")

fill_colors<-c()
for(i in 1:length(hotdogs$New.record)){
if(hotdogs$New.record[i] == 1)
{
fill_colors <- c(fill_colors, "#821122")
}
else
{
fill_colors <- c(fill_colors, "#cccccc")
}
}
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col = fill_colors, border = NA, space=0.3, xlab="Year", ylab="Hot dogs and buns (HDB) eaten")

rgb(0, 1, 0)

barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col="red", border=NA, xlab="Year", ylab="Hot dogs and buns (HDB) eaten")

附图4-5中英文版如下所示:

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

图形空间

文章不错,赞赏鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值