R语言操作练习2

  1. 加载tidyr包,探索table1,table2,table3,table4a, table4b维度和结构

  2. 将table4a进行宽转长操作,列名为country,year,population

  3. 基于题2,以country为横坐标,population为纵坐标,fill=year,采用dodge形式作柱状图,颜色为#022a99和#fbcd08

  4. 基于题2,以country为横坐标,population为纵坐标,fill=year,作堆叠柱状图,颜色为#022a99和#fbcd08

  5. 基于题2,以country为横坐标,population为纵坐标,year作为分面对象,作分面柱状图,主题用theme_bw(),采用Pastel3填充country

  6. 基于题2,以country为横坐标,population为纵坐标,year作为分面对象,作分面柱状图,主题采用theme()

  7. 绘制参考范例中的和弦图

    https://jokergoo.github.io/circlize_book/book/the-chorddiagram-function.html#scaling

  8. 绘制参考范例中的峰峦图

    https://r-graph-gallery.com/294-basic-ridgeline-plot.html

r 复制代码
install.packages("tidyr")
install.packages("ggplot2")
install.packages("dplyr")
install.packages("RColorBrewer")
install.packages("circlize")
install.packages("ggridges")
library(ggridges)
library(tidyr)
library(ggplot2)
library(dplyr)
library(RColorBrewer)
library(circlize)
str(table1)
str(table2)
str(table3)
str(table4a)
str(table4b)
table4a_long <- table4a %>%
  pivot_longer(cols = -country, names_to = "year", values_to = "population")
ggplot(table4a_long, aes(x = country, y = population, fill = year)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("#022a99", "#fbcd08")) +
  theme_minimal()
ggplot(table4a_long, aes(x = country, y = population, fill = year)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("#022a99", "#fbcd08")) +
  theme_minimal()
ggplot(table4a_long, aes(x = country, y = population, fill = country)) +
  geom_bar(stat = "identity") +
  scale_fill_brewer(palette = "Pastel3") +
  facet_wrap(~year, scales = "free_y") +
  theme_bw()
ggplot(table4a_long, aes(x = country, y = population, fill = country)) +
  geom_bar(stat = "identity") +
  facet_wrap(~year, scales = "free_y") +
  theme()
chord_data <- data.frame(
  from = c("A", "B", "C"),
  to = c("D", "E", "F"),
  value = c(10, 20, 30)
)
chordDiagram(chord_data, transparency = 0.5)
ridge_data <- data.frame(
  country = rep(c("Country1", "Country2"), each = 100),
  year = rep(rep(2000:2001, each = 50), times = 2),
  population = rnorm(200, mean = 100, sd = 20)
)
ridge_data$year <- as.factor(ridge_data$year)
ggplot(ridge_data, aes(x = population, y = year, fill = country)) +
  geom_density_ridges(alpha = 0.7, position = "identity", scale = 0.9) +
  scale_fill_manual(values = c("#022a99", "#fbcd08")) +
  labs(title = "Population Distribution by Country and Year",
       x = "Population", y = "Year") +
  theme_ridges()
相关推荐
Lun3866buzha8 小时前
【深度学习】Mask R-CNN在温室番茄成熟度检测中的应用——基于ResNet18与FPN的多级特征融合分类系统
深度学习·r语言·cnn
Katecat9966319 小时前
夜间收费站与道路场景多类型车辆检测与分类:基于Faster R-CNN R50 PAFPN的实现_1
分类·r语言·cnn
Piar1231sdafa1 天前
红枣目标检测Cascade R-CNN改进版_FPN结构优化详解
目标检测·r语言·cnn
天桥下的卖艺者1 天前
R语言绘制复杂加权数据(nhanes数据)多模型生存分析决策曲线
开发语言·r语言
Tiger Z1 天前
《R for Data Science (2e)》免费中文翻译 (第15章) --- Regular expression(1)
数据分析·r语言·数据科学·免费书籍
Dekesas96952 天前
【深度学习】基于Faster R-CNN的黄瓜幼苗智能识别与定位系统,农业AI新突破
人工智能·深度学习·r语言
青啊青斯2 天前
二、PaddlePaddle seal_recognition印章内容提取
人工智能·r语言·paddlepaddle
Piar1231sdafa2 天前
木结构建筑元素识别与分类:基于Faster R-CNN的高精度检测方法
分类·r语言·cnn
Piar1231sdafa2 天前
智能拖拉机目标检测:改进Faster R-CNN的实践与优化
目标检测·r语言·cnn
青春不败 177-3266-05203 天前
HMSC联合物种分布模型在群落生态学中的贝叶斯统计分析应用
随机森林·r语言·生态学·生物多样性·生态环境·生物群落·物种分布