<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Portfolios | Hantong Wang</title><link>https://www.wanghantong.site/portfolio/</link><atom:link href="https://www.wanghantong.site/portfolio/index.xml" rel="self" type="application/rss+xml"/><description>Portfolios</description><generator>Wowchemy (https://wowchemy.com)</generator><language>zh-hans</language><lastBuildDate>Thu, 07 Apr 2022 00:00:00 +0000</lastBuildDate><image><url>https://www.wanghantong.site/media/icon_hua2ec155b4296a9c9791d015323e16eb5_11927_512x512_fill_lanczos_center_3.png</url><title>Portfolios</title><link>https://www.wanghantong.site/portfolio/</link></image><item><title>Chinese GDP - Unbalanced Growth</title><link>https://www.wanghantong.site/portfolio/chinesegdp/</link><pubDate>Thu, 07 Apr 2022 00:00:00 +0000</pubDate><guid>https://www.wanghantong.site/portfolio/chinesegdp/</guid><description>&lt;h3 id="这是我第二次尝试记录我的数据分析结果这次我们把目光移回到国内重点关注">&lt;strong>这是我第二次尝试记录我的数据分析结果，这次我们把目光移回到国内，重点关注：&lt;/strong>&lt;/h3>
&lt;ul>
&lt;li>中国各省市和地区的GDP发展情况&lt;/li>
&lt;li>对各省市的发展快慢进行排名&lt;/li>
&lt;li>探索每个省市和地区的相对发展速度（与平均GDP增长率相比）&lt;/li>
&lt;li>绘制GDP相对增长地图&lt;/li>
&lt;/ul>
&lt;p>所以本文除了涉及之前的柱状图以外，还会展示如何在R中绘制地图。&lt;/p>
&lt;p>&lt;strong>本文的所有数据大部分来源于Kaggle还有中华人民共和国民政部的开放数据，感谢它们！🙏🙏&lt;/strong>&lt;/p>
&lt;h3 id="一各区域gdp增长情况">&lt;strong>一、各区域GDP增长情况&lt;/strong>&lt;/h3>
&lt;p>在本节，我们会将各个省份划分为不同的地区，看看不同地区的GDP发展情况如何。&lt;/p>
&lt;h4 id="首先清洗数据">&lt;strong>首先清洗数据&lt;/strong>&lt;/h4>
&lt;pre tabindex="0">&lt;code class="language-{r" data-lang="{r">#加载包
library(rio)
library(tidyverse)
library(MetBrewer)
library(showtext); showtext_auto()
library(ggmap)
library(mapproj)
library(sf)
library(ggrepel)
library(extrafont)
library(RColorBrewer)
library(cowplot)
library(ragg)
#导入字体
font_add_google(&amp;#34;Calligraffitti&amp;#34;, &amp;#34;call&amp;#34;)
font_add_google(&amp;#34;Kalam&amp;#34;, &amp;#34;kalam&amp;#34;)
font_add_google(&amp;#34;ZCOOL KuaiLe&amp;#34;, &amp;#34;cool&amp;#34;)
&lt;/code>&lt;/pre>&lt;pre tabindex="0">&lt;code class="language-{r" data-lang="{r">#读入数据
china_map = st_read(dsn = &amp;#34;http://xzqh.mca.gov.cn/data/quanguo.json&amp;#34;, stringsAsFactors = FALSE)
st_crs(china_map) &amp;lt;- 4326 #设置地图坐标系统为 WGS84
data1 &amp;lt;- import(&amp;#39;Chinas GDP in Province En.csv&amp;#39;) #GDP数据
line &amp;lt;- st_read(&amp;#39;geojson/九段线GS（2019）1719号.geojson&amp;#39;) #用于绘制南海9段线
#数据预处理
GDP_long &amp;lt;- data1 %&amp;gt;%
rename(Guangxi = `Guangxi,`, #广西省名称有误，修改
year = V1) %&amp;gt;%
pivot_longer(cols = 2:ncol(data1),names_to = &amp;#39;Province&amp;#39;, values_to = &amp;#39;gdp&amp;#39;) %&amp;gt;%
mutate(quhao = case_when(
Province == &amp;#39;Beijing&amp;#39; ~ &amp;#39;110000&amp;#39;,
Province == &amp;#39;Tianjin&amp;#39; ~ &amp;#39;120000&amp;#39;,
Province == &amp;#39;Hebei&amp;#39; ~ &amp;#39;130000&amp;#39;,
Province == &amp;#39;Shanxi&amp;#39; ~ &amp;#39;140000&amp;#39;,
Province == &amp;#39;Inner Mongolia&amp;#39;~ &amp;#39;150000&amp;#39;,
Province == &amp;#39;Liaoning&amp;#39;~ &amp;#39;210000&amp;#39;,
Province == &amp;#39;Jilin&amp;#39;~ &amp;#39;220000&amp;#39;,
Province == &amp;#39;Heilongjiang&amp;#39;~ &amp;#39;230000&amp;#39;,
Province == &amp;#39;Shanghai&amp;#39;~ &amp;#39;310000&amp;#39;,
Province == &amp;#39;Jiangsu&amp;#39;~ &amp;#39;320000&amp;#39;,
Province == &amp;#39;Zhejiang&amp;#39;~ &amp;#39;330000&amp;#39;,
Province == &amp;#39;Anhui&amp;#39;~ &amp;#39;340000&amp;#39;,
Province == &amp;#39;Fujian&amp;#39;~ &amp;#39;350000&amp;#39;,
Province == &amp;#39;Jiangxi&amp;#39;~ &amp;#39;360000&amp;#39;,
Province == &amp;#39;Shandong&amp;#39;~ &amp;#39;370000&amp;#39;,
Province == &amp;#39;Henan&amp;#39;~ &amp;#39;410000&amp;#39;,
Province == &amp;#39;Hubei&amp;#39;~ &amp;#39;420000&amp;#39;,
Province == &amp;#39;Hunan&amp;#39;~ &amp;#39;430000&amp;#39;,
Province == &amp;#39;Guangdong&amp;#39;~ &amp;#39;440000&amp;#39;,
Province == &amp;#39;Guangxi&amp;#39;~ &amp;#39;450000&amp;#39;,
Province == &amp;#39;Hainan&amp;#39;~ &amp;#39;460000&amp;#39;,
Province == &amp;#39;Chongqing&amp;#39;~ &amp;#39;500000&amp;#39;,
Province == &amp;#39;Sichuan&amp;#39;~ &amp;#39;510000&amp;#39;,
Province == &amp;#39;Guizhou&amp;#39;~ &amp;#39;520000&amp;#39;,
Province == &amp;#39;Yunnan&amp;#39;~ &amp;#39;530000&amp;#39;,
Province == &amp;#39;Tibet&amp;#39;~ &amp;#39;540000&amp;#39;,
Province == &amp;#39;Shaanxi&amp;#39;~ &amp;#39;610000&amp;#39;,
Province == &amp;#39;Gansu&amp;#39;~ &amp;#39;620000&amp;#39;,
Province == &amp;#39;Qinghai&amp;#39;~ &amp;#39;630000&amp;#39;,
Province == &amp;#39;Ningxia&amp;#39;~ &amp;#39;640000&amp;#39;,
Province == &amp;#39;Xinjiang&amp;#39;~ &amp;#39;650000&amp;#39;), #为省份赋予区号，便于后续后并数据
area = case_when(substring(quhao,1,1) == &amp;#39;1&amp;#39; ~ &amp;#39;华北&amp;#39;,
substring(quhao,1,1) == &amp;#39;2&amp;#39; ~ &amp;#39;东北&amp;#39;,
substring(quhao,1,1) == &amp;#39;3&amp;#39; ~ &amp;#39;华东&amp;#39;,
quhao %in% c(&amp;#39;410000&amp;#39;,&amp;#39;420000&amp;#39;,&amp;#39;430000&amp;#39;) ~ &amp;#39;华中&amp;#39;,
quhao %in% c(&amp;#39;440000&amp;#39;,&amp;#39;450000&amp;#39;,&amp;#39;460000&amp;#39;) ~ &amp;#39;华南&amp;#39;,
substring(quhao,1,1) == &amp;#39;5&amp;#39; ~ &amp;#39;西南&amp;#39;,
substring(quhao,1,1) == &amp;#39;6&amp;#39; ~ &amp;#39;西北&amp;#39;))
&lt;/code>&lt;/pre>&lt;h4 id="进行可视化展示">&lt;strong>进行可视化展示&lt;/strong>&lt;/h4>
&lt;pre tabindex="0">&lt;code class="language-{r" data-lang="{r">GDP_long %&amp;gt;%
ggplot(aes(x=year, y = gdp))+
facet_wrap(~area,ncol = 2,strip.position = &amp;#34;top&amp;#34;)+
stat_summary(aes(x = year, y = gdp, group = area), fun.y = &amp;#39;mean&amp;#39;, geom = &amp;#39;line&amp;#39;,
size = 0.6, lty = &amp;#39;dotted&amp;#39;,color = &amp;#39;black&amp;#39;)+
geom_line(aes(group = Province,color = quhao),size = 0.6, alpha = 0.7,show.legend = F)+
geom_text_repel(data = GDP_long[GDP_long$year == &amp;#39;2020&amp;#39;,],aes(label = Province),
nudge_y = 1500,max.overlaps = 13, nudge_x = 1, size = 6, alpha = 1, family = &amp;#39;kalam&amp;#39;)+
theme_classic()+
scale_color_manual(values = met.brewer(&amp;#39;Signac&amp;#39;,length(unique(GDP_long$quhao))),guide=&amp;#39;none&amp;#39;)+
labs(x = &amp;#39;Year&amp;#39;, y = &amp;#39;GDP&amp;#39;)+
theme(panel.grid.major = element_line(),
strip.background = element_blank(),
strip.text = element_text(size = 18, family = &amp;#39;wqy-microhei&amp;#39;),
strip.placement = &amp;#39;outside&amp;#39;,
axis.title = element_text(size = 30, family = &amp;#39;kalam&amp;#39;),
axis.text.y = element_text(size = 18,family = &amp;#39;kalam&amp;#39;),
axis.text.x = element_text(size = 14, angle = 10, family = &amp;#39;kalam&amp;#39;),
) -&amp;gt; GDP_line
#ggsave(&amp;#39;GDP/GDP_line.png&amp;#39;,GDP_line, height = 18, width = 32, unit = &amp;#39;cm&amp;#39;, scaling = 1, bg = &amp;#39;white&amp;#39;)
&lt;/code>&lt;/pre>&lt;p>&lt;font size=2>&lt;center>各地区GDP发展时序图&lt;/center>&lt;/font>&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="" srcset="
/portfolio/chinesegdp/GDP_line_hue06a262159f5f17c459b6c4c2e353eda_364052_b211a25fdd29d2392c449539078d93a5.webp 400w,
/portfolio/chinesegdp/GDP_line_hue06a262159f5f17c459b6c4c2e353eda_364052_8ebaf382621deef289568cb53cc7853a.webp 760w,
/portfolio/chinesegdp/GDP_line_hue06a262159f5f17c459b6c4c2e353eda_364052_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://www.wanghantong.site/portfolio/chinesegdp/GDP_line_hue06a262159f5f17c459b6c4c2e353eda_364052_b211a25fdd29d2392c449539078d93a5.webp"
width="760"
height="443"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
我们最终得到了可视化的结果，图中黑色虚线代表了各地区的平均发展速度。从上图大致可以看出 &lt;strong>&lt;em>华东、华南、华中、西南&lt;/em>&lt;/strong> 地区的GDP上升速度是比较快的，而 &lt;strong>&lt;em>华北、西北、东北&lt;/em>&lt;/strong> 则相对缓慢。具体来看：&lt;/p>
&lt;ol>
&lt;li>华东地区发展较快，以江苏、山东、浙江为代表；&lt;/li>
&lt;li>华中地区发展最为均衡，三省之间差异不大；&lt;/li>
&lt;li>华南地区主要由广东带动其发展，其余两省似乎难以望其项背；&lt;/li>
&lt;li>北方的省市均稍显颓势，东北三省的发展均有所落后&lt;/li>
&lt;/ol>
&lt;p>总体来说，图上所呈现的模式大致与我们平时所了解的东南部强势、西北部弱势相吻合。&lt;/p>
&lt;h3 id="二各省市gdp增速排行">&lt;strong>二、各省市GDP增速排行&lt;/strong>&lt;/h3>
&lt;p>本节将会对具体各省市的发展情况进行排名并予以展示。&lt;/p>
&lt;h4 id="数据清洗">&lt;strong>数据清洗&lt;/strong>&lt;/h4>
&lt;pre tabindex="0">&lt;code class="language-{r" data-lang="{r">#数据清洗
GDP_long %&amp;gt;%
pivot_wider(names_from = year,values_from = gdp, names_prefix = &amp;#39;year&amp;#39;,names_sort = T) %&amp;gt;% #将年份长转宽，使得一行观察值代表每个省市
mutate(ratio = (year2020 - year1992)/(year1992)) %&amp;gt;% #计算增长率
arrange(ratio) %&amp;gt;%
mutate(Province = fct_reorder(Province, ratio),
angle = 90 - 360*((as.numeric(Province) - 0.5)/(max(as.numeric(Province))+4)), #+4 流出空白区域
hjust = if_else(angle &amp;lt; -90,1,0),
angle = if_else(angle &amp;lt; -90,angle + 180,angle),
relative = ratio - mean(ratio)) -&amp;gt; GDP_wide
&lt;/code>&lt;/pre>&lt;h4 id="结果可视化---环形柱状图">&lt;strong>结果可视化 - 环形柱状图&lt;/strong>&lt;/h4>
&lt;pre tabindex="0">&lt;code class="language-{r" data-lang="{r">#结果可视化
GDP_wide %&amp;gt;%
ggplot(aes(x= as.numeric(Province), y = ratio)) +
geom_col(aes(fill = ratio),color = &amp;#39;#8F999F&amp;#39;,show.legend = F, size = 0.3)+
coord_polar() +
geom_text(aes(y = ratio+0.2,label = Province, angle = angle, hjust = hjust), vjust = 0.5, size = 7, family = &amp;#39;kalam&amp;#39;) +
scale_y_continuous(expand = c(0,0), limits = c(-10, max(GDP_wide$ratio)+10), labels = scales::percent_format()) +
xlim(c(0,nrow(GDP_wide)+4))+
geom_segment(data = data.frame(x = rep(nrow(GDP_wide)+1,3),
xend = rep(nrow(GDP_wide)+4,3),
y = c(15,30,60),
yend = c(15,30,60)),
aes(x = x, xend = xend , y =y, yend =yend), color = &amp;#39;#8F999F&amp;#39;,size = 0.6) +
geom_segment(aes(x = 0, xend = nrow(GDP_wide)+4, y = 0 , yend = 0),color = &amp;#39;#8F999F&amp;#39;,size = 0.3)+ #内部圆环
geom_text(data = data.frame(label = c(&amp;#39;1,500%&amp;#39;,&amp;#34;3,000%&amp;#34;,&amp;#34;6,000%&amp;#34;),
y = c(15,30,60)),
aes(x = nrow(GDP_wide)+2.5, y = y + 2, label =label),vjust = 0,
angle = 360 - 360*(nrow(GDP_wide)+2.5)/(max(as.numeric(GDP_wide$Province))+4),
size = 8, family = &amp;#39;kalam&amp;#39;,color = &amp;#39;#8F999F&amp;#39;)+
theme_void()+
scale_fill_gradientn(colors=met.brewer(&amp;#34;Tam&amp;#34;, direction = -1)) -&amp;gt; GDP_cycle
#ggsave(&amp;#34;GDP/GDP_cycle.png&amp;#34;, GDP_cycle, width = 6, height = 6, scaling = 1, bg = &amp;#39;white&amp;#39;)
&lt;/code>&lt;/pre>&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="" srcset="
/portfolio/chinesegdp/GDP_cycle_hu21bc885404058f83b0f4eb96214dcd04_396260_bb997a7fba6e96a9235c2b669c87e4b6.webp 400w,
/portfolio/chinesegdp/GDP_cycle_hu21bc885404058f83b0f4eb96214dcd04_396260_28f158d193a6632bd8a82c23acd9e061.webp 760w,
/portfolio/chinesegdp/GDP_cycle_hu21bc885404058f83b0f4eb96214dcd04_396260_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://www.wanghantong.site/portfolio/chinesegdp/GDP_cycle_hu21bc885404058f83b0f4eb96214dcd04_396260_bb997a7fba6e96a9235c2b669c87e4b6.webp"
width="760"
height="760"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>通过环形图可以看到与第一部分的结论一致，东北三省的增长速度确实是最为缓慢的，这可能与中国工业逐步转型有关。但让人惊讶的是上海的排名也位于下半区，这好像与我的理解有出入，这可能跟1992年GDP基数大小有关，西藏位于排头可能也有这方面的原因。为此，下文将进一步将&lt;em>&lt;strong>增量&lt;/strong>&lt;/em>与&lt;em>&lt;strong>增速&lt;/strong>&lt;/em>同时进行考虑，来更好地理解环形图的结果。&lt;/p>
&lt;h4 id="结果可视化---双轴柱状图">&lt;strong>结果可视化 - 双轴柱状图&lt;/strong>&lt;/h4>
&lt;pre tabindex="0">&lt;code class="language-{r" data-lang="{r">#绘制双轴柱状图
GDP_wide %&amp;gt;%
mutate(incs = year2020 - year1992) %&amp;gt;%
ggplot() +
geom_col(aes(x = reorder(Province, -ratio), y = -incs, fill = incs),show.legend = F) +
scale_fill_gradient(low = &amp;#39;#33655b&amp;#39;, high = &amp;#39;#bbded6&amp;#39;)+
new_scale_fill()+
geom_col(aes(x = reorder(Province, -ratio), y = ratio*1000,fill = ratio),show.legend = F)+
scale_fill_gradientn(colors = met.brewer(&amp;#39;Hokusai2&amp;#39;, direction = -1))+
scale_y_continuous(breaks = c(seq(-90000, 0, 30000), c(20000, 40000, 60000)),
labels = c(&amp;#34;90000&amp;#34;,&amp;#34;60000&amp;#34;,&amp;#34;30000&amp;#34;,&amp;#34;0&amp;#34;,&amp;#34;&amp;#34;,&amp;#34;&amp;#34;,&amp;#34;&amp;#34;),
sec.axis = sec_axis(~ ./10, name = &amp;#34;GDP增速(%)&amp;#34;,
breaks = seq(0, 6000,2000))) +
geom_text(aes(x = reorder(Province, -ratio), y = ratio*1000,
label = paste0(scales::comma(round(ratio*100),1.0),&amp;#34;%&amp;#34;)),
hjust = 0.4, vjust = -0.5, size =6.5, family = &amp;#39;call&amp;#39;) +
geom_text(aes(x = reorder(Province, -ratio), y = -incs,
label = scales::comma(incs,1.0)),
hjust = 0.5, vjust = 1.5, size =6.5, family = &amp;#39;call&amp;#39;) +
geom_hline(aes(yintercept = 0), size = 0.6 , color = &amp;#34;white&amp;#34;) +
theme_minimal()+
labs(y =&amp;#34; GDP增量（亿元）&amp;#34;)+
theme(panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_line(size = 0.4, color = &amp;#39;darkgray&amp;#39;),
panel.grid.minor.y = element_line(size = 0.3, color = &amp;#39;lightgray&amp;#39;),
axis.text.y = element_text(size = 18, family = &amp;#39;kalam&amp;#39;),
axis.title.y.left = element_text(hjust = 0.28, size = 32, vjust = 2),
axis.title.y.right = element_text(hjust = 0.12, size = 32, vjust = 2),
axis.title.x = element_blank(),
axis.text.x = element_text(size = 18, family = &amp;#39;kalam&amp;#39;, angle = 15, hjust = 0.5)) -&amp;gt; compare_col
ggsave(&amp;#34;GDP/GDP_two_axes.png&amp;#34;, compare_col, width = 12, height = 6,bg = &amp;#39;white&amp;#39;)
&lt;/code>&lt;/pre>&lt;p>&lt;font size=2>&lt;center>各省市GDP增速与增量&lt;/center>&lt;/font>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="" srcset="
/portfolio/chinesegdp/GDP_two_axes_hu26c8c53fd9e9603d912070f0e2c20f7d_248865_e73cd7a3879b69150a983a1db2483e87.webp 400w,
/portfolio/chinesegdp/GDP_two_axes_hu26c8c53fd9e9603d912070f0e2c20f7d_248865_9cfab658df815790492e60d522c0444f.webp 760w,
/portfolio/chinesegdp/GDP_two_axes_hu26c8c53fd9e9603d912070f0e2c20f7d_248865_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://www.wanghantong.site/portfolio/chinesegdp/GDP_two_axes_hu26c8c53fd9e9603d912070f0e2c20f7d_248865_e73cd7a3879b69150a983a1db2483e87.webp"
width="760"
height="380"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>将这部分的结果结合环形图来看的话，可以发现一些地区虽然增速较快的实际的增量却不是很大，尤其是西部的地区比如西藏、宁夏、青海等。江苏和广东则是增量大的同时增速也很快。而浙江属于增速快而增量较大、上海增量较大而增速相对较缓。而东北三省在考虑到增量以后仍不容乐观。因此如何进一步促进西部与北部地区的发展仍然是我们需要去解决的问题。&lt;/p>
&lt;h3 id="三中国gdp地图">&lt;strong>三、中国GDP地图&lt;/strong>&lt;/h3>
&lt;p>本节将继续考虑各省市的GDP相对增长速度,本文对其的定义是：&lt;u>&lt;em>相对于平均增长速度的差异&lt;/em>&lt;/u>。并将结果用地图的形式绘制出来。&lt;/p>
&lt;h4 id="数据清洗-1">&lt;strong>数据清洗&lt;/strong>&lt;/h4>
&lt;pre tabindex="0">&lt;code class="language-{r" data-lang="{r">#数据清洗
GDP_map &amp;lt;- china_map %&amp;gt;%
rename(quhao = QUHUADAIMA) %&amp;gt;%
mutate(quhao = case_when(quhao== &amp;#39;daodian&amp;#39; ~ NAME,
TRUE ~ quhao)) %&amp;gt;%
select(quhao,geometry) %&amp;gt;%
left_join(GDP_wide, by = &amp;#39;quhao&amp;#39;) %&amp;gt;%
select(Province,ratio, geometry, relative) %&amp;gt;%
mutate(hjust = if_else(relative &amp;gt;= 0, 0,1),
type = case_when(relative &amp;gt;= 15 ~ 1,
10 &amp;lt;= relative &amp;amp; relative &amp;lt; 15 ~ 2,
5 &amp;lt;= relative &amp;amp; relative &amp;lt; 10 ~ 3,
0 &amp;lt;= relative &amp;amp; relative &amp;lt; 5 ~ 4,
-5 &amp;lt;= relative &amp;amp; relative &amp;lt; 0 ~ 5,
-10 &amp;lt;= relative &amp;amp; relative &amp;lt; -5 ~ 6,
-15 &amp;lt;= relative &amp;amp; relative &amp;lt; -10 ~ 7,
relative &amp;lt; -15 ~ 8),
type = factor(as.character(type)),
fill = case_when(type == &amp;#34;1&amp;#34; ~ &amp;#34;#FC4E2A&amp;#34;,
type == &amp;#34;2&amp;#34; ~ &amp;#34;#FD8D3C&amp;#34;,
type == &amp;#34;3&amp;#34; ~ &amp;#34;#FEB24C&amp;#34;,
type == &amp;#34;4&amp;#34; ~ &amp;#34;#FED976&amp;#34;,
type == &amp;#34;5&amp;#34; ~ &amp;#34;#C6DBEF&amp;#34;,
type == &amp;#34;6&amp;#34; ~ &amp;#34;#9ECAE1&amp;#34;,
type == &amp;#34;7&amp;#34; ~ &amp;#34;#6BAED6&amp;#34;,
type == &amp;#34;8&amp;#34; ~ &amp;#34;#2470a0&amp;#34;,
TRUE ~ &amp;#34;lightgrey&amp;#34;))%&amp;gt;%
arrange(desc(relative))
&lt;/code>&lt;/pre>&lt;h4 id="结果可视化">&lt;strong>结果可视化&lt;/strong>&lt;/h4>
&lt;h5 id="主要地图">&lt;strong>主要地图&lt;/strong>&lt;/h5>
&lt;pre tabindex="0">&lt;code>#绘制主要地图
GDP_map %&amp;gt;%
ggplot()+
geom_sf(aes(fill = fill, geometry = geometry),show.legend = F,color = &amp;#39;lightgrey&amp;#39;, size = 0.5) +
scale_fill_identity()+
theme_void()+
theme(aspect.ratio = 0.93) -&amp;gt; MGDP
&lt;/code>&lt;/pre>&lt;h5 id="南海九段线">&lt;strong>南海九段线&lt;/strong>&lt;/h5>
&lt;pre tabindex="0">&lt;code>#绘制南海九段线
GDP_map %&amp;gt;%
ggplot()+
geom_sf(aes(fill = fill, geometry = geometry),show.legend = F,color = &amp;#39;lightgrey&amp;#39;, size = 0.5) +
scale_fill_identity()+
geom_sf(data = line) +
coord_sf(xlim = c(108,124), ylim = c(2,24))+
theme(aspect.ratio = 1.5, #调节长宽比
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(), #panel - 分面或者单图的画布信息
panel.background = element_blank(),
panel.border = element_rect(fill=NA, color=&amp;#34;grey10&amp;#34;,linetype=1,size=0.5),
plot.margin=unit(c(0,0,0,0),&amp;#34;mm&amp;#34;)) -&amp;gt; nine_line
&lt;/code>&lt;/pre>&lt;h5 id="相对发展柱状图">&lt;strong>相对发展柱状图&lt;/strong>&lt;/h5>
&lt;pre tabindex="0">&lt;code>GDP_map %&amp;gt;%
mutate(Province = fct_reorder(Province, relative),
label = paste0(Province,&amp;#34;(&amp;#34;,scales::comma(round(relative*100),1),&amp;#34;%&amp;#34;,&amp;#34;)&amp;#34;)) %&amp;gt;%
distinct(Province, .keep_all = T) %&amp;gt;%
filter(!is.na(Province)) %&amp;gt;%
ggplot()+
geom_col(aes(x=Province,y = relative, fill = fill, color = fill)) +
scale_fill_identity()+
scale_color_identity()+
coord_flip()+
geom_text(aes(x = Province, y = relative+0.2 - hjust * 0.4 ,label = label, hjust = hjust), vjust = 0.5, size = 7, family = &amp;#39;kalam&amp;#39;) +
scale_y_continuous(labels = scales::percent_format(), limits = c(-27,20)) +
theme_classic()+
theme(axis.ticks= element_blank(),
axis.line = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5,size = 18),
plot.margin= margin(0,8,0,8,unit = &amp;#39;mm&amp;#39;)) -&amp;gt; relative_plot
&lt;/code>&lt;/pre>&lt;h5 id="合并图片">&lt;strong>合并图片&lt;/strong>&lt;/h5>
&lt;pre tabindex="0">&lt;code>text = &amp;#39;自1992年以来各省的GDP都呈现快速的增长模式，但从此部分的可\n视化结果可以发现，各省虽都处于快速发展阶段，但省之间的相对\n发展速度存在明显差异。西藏、福建、重庆、贵州与北京是相对增\n速最快的五个省市，而东北三省以及河北与甘肃的增速相对缓慢。\n从地理分布图上也可以看出，除去GDP基数较小的西藏与内蒙古以\n外,南北间存在着明显差距。&amp;#39;
ggdraw(xlim = c(0.15,1),ylim = c(0,1))+
draw_plot(relative_plot,x = 0.57, y = 0.5,hjust = 0.5, vjust = 0.5, width = 0.85,height = 0.95)+
draw_plot(MGDP, x = 0.8, y = 0.20,hjust = 0.5, vjust = 0.5,width = 0.65,height = 0.65)+
draw_plot(nine_line, x = 0.95, y = 0.12,hjust = 0.5, vjust = 0.5, width = 0.15,height = 0.15)+
draw_text(&amp;#39;1992~2020年中国各省份GDP相对增长速率&amp;#39;,x = 0.39, y = 0.94,hjust = 0.5, vjust = 0.5, size = 54, family = &amp;#39;cool&amp;#39;)+
draw_text(text,x = 0.26, y = 0.75,hjust = 0, vjust = 0.5, size = 28, lineheight = 1, family = &amp;#39;cool&amp;#39;) -&amp;gt; final_plot
final_plot
ggsave(&amp;#39;GDP/GDP_MAP.png&amp;#39;,final_plot, height = 18, width = 32, unit = &amp;#39;cm&amp;#39;, scaling = 0.6, bg = &amp;#39;white&amp;#39;)
&lt;/code>&lt;/pre>&lt;p>&lt;font size=2>&lt;center>1992-2020GDP相对增长&lt;/center>&lt;/font>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="" srcset="
/portfolio/chinesegdp/GDP_MAP_hu383e3b4fcd860045c77775dd0af42770_581481_6f91afeb41a3abfac79383c72a0c60db.webp 400w,
/portfolio/chinesegdp/GDP_MAP_hu383e3b4fcd860045c77775dd0af42770_581481_899310be10c51cd47e8abc740d48a4d5.webp 760w,
/portfolio/chinesegdp/GDP_MAP_hu383e3b4fcd860045c77775dd0af42770_581481_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://www.wanghantong.site/portfolio/chinesegdp/GDP_MAP_hu383e3b4fcd860045c77775dd0af42770_581481_6f91afeb41a3abfac79383c72a0c60db.webp"
width="760"
height="428"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>正如图上所描述的：自1992年以来,近30年间各省的GDP都呈现向上增长的发展模式，但省之间的发展速度存在明显差异。西藏、福建、重庆、贵州与北京相对增速最快，而东北三省以及河北与甘肃的增速相对缓慢。从地图的分布上看，再次通过另一种形式表现出了南、北与东、西之间的发展差异。&lt;/p>
&lt;p>本次的内容结束了，内容并不是很多。如果有什么建议或者问题欢迎联系我📱💌 或者给我留言~&lt;/p></description></item><item><title>Billboard - TOP100</title><link>https://www.wanghantong.site/portfolio/billboard/</link><pubDate>Mon, 21 Mar 2022 00:00:00 +0000</pubDate><guid>https://www.wanghantong.site/portfolio/billboard/</guid><description>
&lt;div id="本文利用开放r包-billboard-中的数据" class="section level3">
&lt;h3>&lt;strong>本文利用开放R包 &lt;em>billboard&lt;/em> 中的数据：&lt;/strong>&lt;/h3>
&lt;ul>
&lt;li>展示如何利用R以及ggplot2包进行数据分析并形成出版级别的可视化效果&lt;/li>
&lt;li>展现2016年年度十大歌手及其代表作品&lt;/li>
&lt;li>分析半个多世纪以来，年度Top100歌曲在某些特征上的时间变化&lt;/li>
&lt;li>对比1960年与2015年的歌曲特征，揭示不同时代的受欢迎的音乐特点&lt;/li>
&lt;/ul>
&lt;p>文章包括分析代码、可视化结果以及相关的分析结论。&lt;/p>
&lt;p>&lt;strong>话不多说，直接进入正题&lt;/strong>&lt;/p>
&lt;/div>
&lt;div id="一前期准备" class="section level3">
&lt;h3>&lt;strong>一、前期准备&lt;/strong>&lt;/h3>
&lt;pre class="r">&lt;code>#首先加载会使用到的包
library(tidyverse)
library(MetBrewer)
library(cowplot)
library(billboard)
library(extrafont)
library(cowplot)
library(showtext); showtext_auto()
library(ggcorrplot)
library(ggsci)
library(gghalves)
library(ggprism)
library(ggsignif)
library(car)
library(ggbump)
#从GoogleFonts导入字体
font_add_google(&amp;quot;Satisfy&amp;quot;, &amp;quot;satisfy&amp;quot;)
font_add_google(&amp;quot;Sacramento&amp;quot;, &amp;quot;mento&amp;quot;)
font_add_google(&amp;quot;Lobster&amp;quot;, &amp;quot;lobster&amp;quot;)
font_add_google(&amp;quot;Luckiest Guy&amp;quot;, &amp;quot;luck&amp;quot;)
font_add_google(&amp;quot;Calligraffitti&amp;quot;, &amp;quot;call&amp;quot;)
font_add_google(&amp;quot;Kalam&amp;quot;, &amp;quot;kalam&amp;quot;)
font_add_google(&amp;quot;ZCOOL KuaiLe&amp;quot;, &amp;quot;cool&amp;quot;)&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>#读入数据
head(spotify_track_data)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>## # A tibble: 6 x 23
## year artist_name artist_id explicit track_name track_id danceability energy
## &amp;lt;chr&amp;gt; &amp;lt;chr&amp;gt; &amp;lt;chr&amp;gt; &amp;lt;lgl&amp;gt; &amp;lt;chr&amp;gt; &amp;lt;chr&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1 1960 Percy Faith ~ 24DQLSng~ FALSE &amp;quot;The Them~ 2kKL5kk~ 0.466 0.389
## 2 1960 Jim Reeves 2Ev0e8GU~ FALSE &amp;quot;He&amp;#39;ll Ha~ 7DH5dXV~ 0.554 0.186
## 3 1960 Johnny Prest~ 1B8n8vtE~ FALSE &amp;quot;Running ~ 60DbxCJ~ 0.758 0.462
## 4 1960 Mark Dinning 55Rf9Kfq~ FALSE &amp;quot;Teen Ang~ 7GvhZ0F~ 0.583 0.168
## 5 1960 Brenda Lee 4cPHsZM9~ FALSE &amp;quot;I&amp;#39;m Sorr~ 5VyBNCS~ 0.567 0.141
## 6 1960 Elvis Presley 43ZHCT0c~ FALSE &amp;quot;It&amp;#39;s Now~ 2u8Lrq2~ 0.635 0.391
## # ... with 15 more variables: key &amp;lt;int&amp;gt;, loudness &amp;lt;dbl&amp;gt;, mode &amp;lt;int&amp;gt;,
## # speechiness &amp;lt;dbl&amp;gt;, acousticness &amp;lt;dbl&amp;gt;, instrumentalness &amp;lt;dbl&amp;gt;,
## # liveness &amp;lt;dbl&amp;gt;, valence &amp;lt;dbl&amp;gt;, tempo &amp;lt;dbl&amp;gt;, type &amp;lt;chr&amp;gt;, uri &amp;lt;chr&amp;gt;,
## # track_href &amp;lt;chr&amp;gt;, analysis_url &amp;lt;chr&amp;gt;, duration_ms &amp;lt;int&amp;gt;,
## # time_signature &amp;lt;int&amp;gt;&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>head(wiki_hot_100s)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>## no title artist year
## 1 1 Theme from A Summer Place Percy Faith 1960
## 2 2 He&amp;#39;ll Have to Go Jim Reeves 1960
## 3 3 Cathy&amp;#39;s Clown The Everly Brothers 1960
## 4 4 Running Bear Johnny Preston 1960
## 5 5 Teen Angel Mark Dinning 1960
## 6 6 I&amp;#39;m Sorry Brenda Lee 1960&lt;/code>&lt;/pre>
&lt;p>从表格中可以看到&lt;strong>wiki_hot_100s&lt;/strong>数据反映了从1960年到2016年的年度TOP100单曲，包含四个变量：&lt;/p>
&lt;ol style="list-style-type: decimal">
&lt;li>歌曲排行：no&lt;/li>
&lt;li>歌曲名称：title&lt;/li>
&lt;li>歌手名称：artist&lt;/li>
&lt;li>歌曲年份：year&lt;/li>
&lt;/ol>
&lt;p>&lt;strong>spotify_track_data&lt;/strong>数据则反映了其中大部分歌曲在多个特征维度上的评价情况&lt;/p>
&lt;p>🙌前期工作完成🙌&lt;/p>
&lt;p>下面尝试对这些数据进行分析，看看能不能得到什么有趣的结果&lt;/p>
&lt;/div>
&lt;div id="二正式分析" class="section level3">
&lt;h3>&lt;strong>二、正式分析&lt;/strong>&lt;/h3>
&lt;div id="歌手排名" class="section level4">
&lt;h4>&lt;strong>1.歌手排名&lt;/strong>&lt;/h4>
&lt;p>经过大致的数据浏览，我决定选取2016年的数据，以&lt;strong>歌曲上榜数量&lt;/strong>以及&lt;strong>歌曲平均排行&lt;/strong>为指标，决出当年的十大歌手。&lt;/p>
&lt;pre class="r">&lt;code>#数据清洗
singer &amp;lt;- wiki_hot_100s %&amp;gt;%
mutate(year = as.numeric(year),
no = as.numeric(no)) %&amp;gt;%
filter(year %in% 2016 &amp;amp; no &amp;lt;= 100) %&amp;gt;% #选出目标数据并过滤缺失数据
group_by(artist) %&amp;gt;%
mutate(best = min(no),
num = n(),
no_all = sum(no)) %&amp;gt;% #找到每个歌手的最佳作品和上榜歌曲总数
ungroup %&amp;gt;%
mutate(mean_no = no_all/num) %&amp;gt;%
arrange(desc(num), mean_no) %&amp;gt;%
group_by(artist) %&amp;gt;%
mutate(rank = 1:n()) %&amp;gt;%
filter(rank == 1) %&amp;gt;%
select(-c(year,rank,no)) %&amp;gt;%
ungroup() %&amp;gt;%
mutate(rank = row_number())
#选择前10歌手
top_10 &amp;lt;- singer[1:10,] %&amp;gt;%
mutate( angle = 360 - rank*(360 / (max(rank)+1)),
angle = ifelse(angle &amp;lt; -90, angle +180, angle),
mean_no = round(mean_no)) #计算平均歌曲排名&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>#结果可视化
image = &amp;quot;https://raw.githubusercontent.com/wht9975/website/master/images/loveuself.png&amp;quot;
#子图1
top_10 %&amp;gt;%
ggplot()+
ggimage::geom_image(aes(x = 0, y = -1.5, image = image),size=0.19) +
geom_col(aes(x=rank, y=num, fill = artist),show.legend = F, width = 0.95)+
coord_polar(theta = &amp;#39;x&amp;#39;,direction = 1,start = -0.3)+
ylim(c(-1.5,5))+
xlim(c(0,11))+
theme_void()+
geom_text(aes(x = rank, y=as.numeric(num)+1,label = artist),
size=18, family = &amp;#39;satisfy&amp;#39;, fontface = &amp;#39;bold&amp;#39;, vjust = -0.1) +
geom_text(aes(x = rank, y=as.numeric(num)+1,label = paste(title,&amp;#39;-&amp;#39;,best)),
size=11, family = &amp;#39;call&amp;#39;, fontface = &amp;#39;bold&amp;#39;, vjust = 1.7, color = &amp;#39;#716e77&amp;#39;, hjust = 0.55) +
geom_text(aes(x = 0.25, y=2.8),label = &amp;#39;The year of&amp;#39;,
size=28, family = &amp;#39;lobster&amp;#39;, fontface = &amp;#39;bold&amp;#39;, hjust = 1)+
geom_text(data = data.frame(label=factor(c(&amp;#39;2&amp;#39;,&amp;#39;0&amp;#39;,&amp;#39;1&amp;#39;,&amp;#39;6&amp;#39;)),
y = c(12/4, 9/4, 6/4, 3/4)),
aes(x = c(0.5,0.5,0.45,0.5) , y = y , label = label),vjust = 1,hjust = 1,
size = 25, family = &amp;#39;kalam&amp;#39;, fontface = &amp;#39;bold&amp;#39;) +
geom_text(aes(x = rank, y=as.numeric(num)/2, label = rank, size =rank),
color = &amp;#39;white&amp;#39;,family = &amp;#39;kalam&amp;#39;,show.legend = F) +
scale_size_continuous(range = c(32,16)) +
scale_fill_manual(values = met.brewer(&amp;#39;Hokusai1&amp;#39;,n=10)) -&amp;gt;song_2016
#子图2
top_10 %&amp;gt;%
ggplot(aes(x = rank, y = 100 - mean_no, fill = artist))+
geom_col(aes(y=100),color = &amp;#39;lightgrey&amp;#39;,fill = &amp;#39;white&amp;#39;, lty = &amp;#39;dashed&amp;#39;, size = 0.8)+
geom_col(aes(color = artist),show.legend = F,size = 0.8)+
scale_fill_manual(values = met.brewer(&amp;#39;Hokusai1&amp;#39;,n=10))+
scale_color_manual(values = met.brewer(&amp;#39;Hokusai1&amp;#39;,n=10))+
geom_hline(yintercept = c(50,75),color = &amp;#39;#716e77&amp;#39;,lty = &amp;#39;dashed&amp;#39;,size = 0.8)+
geom_text(aes(y = -4, label = artist),
size=14, family = &amp;#39;satisfy&amp;#39;, fontface = &amp;#39;bold&amp;#39;)+
theme_minimal()+
theme(panel.grid = element_blank(),
# axis.line.x = element_line(size = 2),
axis.title = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_text(family = &amp;#39;kalam&amp;#39;,size = 64, hjust = 0.5),
plot.margin = margin(8,2,1,2,unit = &amp;#39;mm&amp;#39;)) +
scale_x_continuous(expand = c(0,0))+
scale_y_continuous(breaks=c(0,50,75,100, 120), labels = c(&amp;#39;&amp;#39;,50,25,1, &amp;#39;&amp;#39;)) -&amp;gt; song_col
#图片合并
ggdraw()+
draw_plot(song_2016, x = 0.025,y = 0.175,width = 0.95,height = 0.95)+
draw_plot(song_col, x = 0.125, y = 0.025,width = 0.75,height = 0.35)+
draw_plot_label(c(&amp;quot;M&amp;quot;,&amp;quot;e&amp;quot;,&amp;quot;a&amp;quot;,&amp;quot;n&amp;quot;), x = rep((0.07),4), y = seq(0.35,0.15,length.out=4),
size = 96, family = &amp;#39;kalam&amp;#39;,hjust = 0.5)+
draw_plot_label(c(&amp;quot;R&amp;quot;,&amp;quot;a&amp;quot;,&amp;quot;n&amp;quot;,&amp;quot;k&amp;quot;), x = rep((0.095),4), y = seq(0.32,0.15,length.out=4),
size = 84, family = &amp;#39;kalam&amp;#39;,hjust = 0.5) -&amp;gt; song_all
#ggsave(&amp;quot;2016.png&amp;quot;, song_all, width = 16, height = 9, units = &amp;#39;in&amp;#39;,bg = &amp;#39;white&amp;#39;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="2016.png" />&lt;/p>
&lt;p>通过环形图可以看到&lt;strong>Justin Bieber&lt;/strong>凭借其&lt;strong>Love Yourself&lt;/strong>（总排名1）以及总共三首上榜歌曲荣登2016年度榜首。排名其后的是&lt;strong>Twenty One Pilots&lt;/strong>、&lt;strong>Adele&lt;/strong>以及&lt;strong>The Weekend&lt;/strong>均有三首佳作上榜。之后的几名歌手均有两首歌曲进入Top100,根据他们的平均歌曲排名（下方柱状图）确定最终排名。&lt;/p>
&lt;/div>
&lt;div id="特征关联" class="section level4">
&lt;h4>&lt;strong>2.特征关联&lt;/strong>&lt;/h4>
&lt;p>本部分尝试分析Spotify在评定歌曲时依据的各项指标间的关系，并通过相关图展示最后结果&lt;/p>
&lt;pre class="r">&lt;code>#数据清洗
feather &amp;lt;- spotify_track_data %&amp;gt;%
rename(artist=artist_name,
title = track_name) %&amp;gt;%
group_by(year) %&amp;gt;%
mutate(rank = 1:n()) %&amp;gt;%
ungroup
feather_all &amp;lt;- feather %&amp;gt;%
select(-c(year,artist,artist_id,track_href,title,track_id,key,type,uri,analysis_url,duration_ms,time_signature,explicit)) #去除无关数据
cor = round(cor(feather_all, method = &amp;#39;pearson&amp;#39;),2) #对特征变量间进行两两相关分析
p.mat &amp;lt;- cor_pmat(feather_all) #计算相关显著性&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>#数据可视化
ggcorrplot(cor, method = &amp;#39;circle&amp;#39;,hc.order = TRUE,
outline.color = &amp;quot;white&amp;quot;,type = &amp;quot;lower&amp;quot;,
lab = F, digits = 2,lab_size = 4, lab_col = &amp;#39;black&amp;#39;,
colors = c(&amp;#39;#128b8e&amp;#39;,&amp;#39;#FFF5C3&amp;#39;,&amp;quot;#fb3c3c&amp;quot;),
ggtheme = theme_minimal())+
guides(fill = guide_colorbar(direction = &amp;#39;horizontal&amp;#39;,
barwidth = unit(12,&amp;#39;cm&amp;#39;),
ticks = F)) +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 28, angle = 30,family = &amp;#39;call&amp;#39;, hjust = 0.6, vjust = 0.9),
axis.text.y = element_text(size = 28, family = &amp;#39;call&amp;#39;),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
plot.margin = margin(20,3,3,3,unit = &amp;#39;mm&amp;#39;),
legend.title = element_blank(),
legend.text = element_text(size = 20,family = &amp;#39;mento&amp;#39;),
legend.position = (&amp;#39;top&amp;#39;)) -&amp;gt; corplot
#ggsave(&amp;quot;feather_cor.png&amp;quot;, corplot,width = 20, height = 20, units = &amp;#39;cm&amp;#39;,bg = &amp;#39;white&amp;#39;,dpi = 300)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="feather_cor.png" />&lt;/p>
&lt;p>相关图中的变量各自代表的含义如下：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>danceability:&lt;/strong> 反应曲目适合跳舞的程度。0代表最不适合跳舞，1代表最适合跳舞。&lt;/li>
&lt;li>&lt;strong>valence:&lt;/strong> 取值由0至1，用于描述曲目所传达的情绪效价（激动、高兴）。得分高者听起来更积极反之更消极（悲伤、痛苦）。&lt;/li>
&lt;li>&lt;strong>speechiness:&lt;/strong> 用于检测曲目中是否存在类似说话的声音。歌曲越像语音（如脱口秀、有声读物、诗歌），值越接近1。高于0.66代表基本由话语组成的曲目。介于0.33和0.66之间可能同时包含音乐和语音，（说唱音乐）。低于0.33最有可能表示音乐和其他非语音曲目。&lt;/li>
&lt;li>&lt;strong>energy:&lt;/strong> 从0到1代表感知到的强度和能量。&lt;/li>
&lt;li>&lt;strong>loudness:&lt;/strong> 整体响度（以分贝为单位）。&lt;/li>
&lt;li>&lt;strong>mode:&lt;/strong> 0,1取值，0代表小调，1代表大调。&lt;/li>
&lt;li>&lt;strong>acousticness:&lt;/strong> 0到1，值越大越有可能是原声音乐。&lt;br />
&lt;/li>
&lt;li>&lt;strong>instrumentalness:&lt;/strong> 0到1，判断乐曲是否不包含人声，越接近1与可能是纯乐器演奏。&lt;/li>
&lt;li>&lt;strong>rank:&lt;/strong> 该歌曲在当年的Top100排名。&lt;/li>
&lt;li>&lt;strong>liveness:&lt;/strong> 通过歌曲中是否存在观众声音来判断歌曲是否是live版本。&lt;/li>
&lt;li>&lt;strong>tempo:&lt;/strong> 曲目的总体节奏（每分钟节拍数，BPM）。&lt;/li>
&lt;/ul>
&lt;p>通过相关热图可以发现：&lt;/p>
&lt;ol style="list-style-type: decimal">
&lt;li>歌曲&lt;strong>效价（valence）与舞动性（danceability）&lt;/strong>、&lt;strong>能量值（energy）与响度（loudness）&lt;/strong>以及&lt;strong>效价（valence）与能量值（energy）&lt;/strong>之间存在较高的&lt;strong>正相关&lt;/strong>。说明这些变量共同反映了歌曲动感、活泼的一个方面&lt;/li>
&lt;li>&lt;strong>原声性（acousticness）与能量值（energy）、响度（loudness）以及舞动性（danceability&lt;/strong>）间均有较高的&lt;strong>负相关&lt;/strong>，这可能是由于原声音乐都是比较柔和、安静的所以与一些动感的音乐元素匹配不佳。&lt;/li>
&lt;li>而歌曲的排名与其他变量间并没有特别的相关。反映了听众的音乐品味是&lt;strong>多元化&lt;/strong>的，并没有那种特征元素特别受到大家的欢迎&lt;/li>
&lt;/ol>
&lt;/div>
&lt;div id="时代变化" class="section level4">
&lt;h4>&lt;strong>3.时代变化&lt;/strong>&lt;/h4>
&lt;p>第三部分选取&lt;strong>四个特征&lt;/strong>（danceability、valence、energy以及speechiness）展示从1960年以来这些特征的时代变化&lt;/p>
&lt;pre class="r">&lt;code>#数据清洗
feather_year &amp;lt;- feather %&amp;gt;%
select(year, title, artist, danceability, valence, energy, instrumentalness,rank, speechiness) %&amp;gt;%
group_by(year) %&amp;gt;%
summarise(mean_dance = mean(danceability),
mean_valence = mean(valence),
mean_energy = mean(energy),
mean_speechiness = mean(speechiness)) %&amp;gt;%
pivot_longer(c(mean_dance,mean_valence,mean_energy,mean_speechiness), names_to = &amp;#39;index&amp;#39;, values_to = &amp;#39;value&amp;#39;)
#数据可视化
feather_year %&amp;gt;%
ggplot(aes(x = year, y = value, group = index, color = index))+
geom_point(aes(fill = index, shape = index),size =2, alpha = 0.8)+
geom_smooth(aes(fill= index), #对数据进行线性拟合
span = 0.6, size = 0.8,
method = &amp;quot;loess&amp;quot;,
level=0.95,
formula = &amp;#39;y~x&amp;#39;, alpha = 0.5) +
scale_fill_manual(values = c(&amp;#39;#2E94B9&amp;#39;,&amp;#39;#F0B775&amp;#39;,&amp;#39;#3b9a9c&amp;#39;,&amp;#39;#D25565&amp;#39;),
labels = c(&amp;#39;Danceability&amp;#39;,&amp;#39;Energy&amp;#39;,&amp;#39;Speechiness&amp;#39;,&amp;#39;Valence&amp;#39;))+
scale_color_manual(values = c(&amp;#39;#2E94B9&amp;#39;,&amp;#39;#F0B775&amp;#39;,&amp;#39;#3b9a9c&amp;#39;,&amp;#39;#D25565&amp;#39;),
labels = c(&amp;#39;Danceability&amp;#39;,&amp;#39;Energy&amp;#39;,&amp;#39;Speechiness&amp;#39;,&amp;#39;Valence&amp;#39;))+
scale_shape_manual(values = c(21,22,23,24),
labels = c(&amp;#39;Danceability&amp;#39;,&amp;#39;Energy&amp;#39;,&amp;#39;Speechiness&amp;#39;,&amp;#39;Valence&amp;#39;))+
theme_minimal()+
labs(x = &amp;#39;&amp;#39;, y = &amp;quot;Score&amp;quot;, title = &amp;#39;Feathers of each Year&amp;#39;)+
theme(legend.title = element_blank(),
legend.text = element_text(size = 18, family = &amp;#39;call&amp;#39;),
legend.position = &amp;#39;top&amp;#39;,
axis.text.x = element_text(size = 18, angle = 15,family = &amp;#39;call&amp;#39;,
hjust = 0.5, vjust = 0.9),
axis.text.y = element_text(size = 24, family = &amp;#39;call&amp;#39;),
axis.title = element_text(size = 40, family = &amp;#39;kalam&amp;#39;),
plot.title = element_text(size = 60, family = &amp;#39;kalam&amp;#39;, hjust = 0.5)) -&amp;gt;feather_plot
ggsave(&amp;quot;feather.png&amp;quot;,feather_plot, width = 12,height = 6, units = &amp;#39;in&amp;#39;, bg = &amp;#39;white&amp;#39;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="feather.png" />
时序图上得出一些有意思的结论：&lt;/p>
&lt;ol style="list-style-type: decimal">
&lt;li>虽然danceability,energy和valence之间存在高相关，但top100歌曲的这三个特征的时代变化却略有差异，人们对于存在高能量值的歌曲越发喜爱，但对歌曲本身效价的选择却由大多为积极的音乐转变为中性的音乐，考虑到数据的平均属性，&lt;strong>这可能反映了近年听众开始更多聆听带有悲伤情感的音乐&lt;/strong>。&lt;/li>
&lt;li>speechiness维度上的变化幅度虽然不大，但也能从一定程度上反映出从90年代开始，&lt;strong>人们对带有说话性质的歌曲（可能以说唱歌曲为代表）的认可度有所提升&lt;/strong>。这与8、90年代说唱逐渐流行的情况也是吻合的&lt;/li>
&lt;/ol>
&lt;/div>
&lt;div id="v.s.-2015" class="section level4">
&lt;h4>&lt;strong>4.1960 V.S. 2015&lt;/strong>&lt;/h4>
&lt;p>由于第三部分的分析发现了歌曲特征在时代上的变化，本部分重点选取最早的1960年代的数据以及数据集中最新的2015年代的数在效价、舞动性以及能量值上进行直接的对比来验证之前的结论。&lt;/p>
&lt;pre class="r">&lt;code>#数据清理
compare &amp;lt;- feather %&amp;gt;%
filter(year %in% c(&amp;#39;1960&amp;#39;,&amp;#39;2015&amp;#39;)) %&amp;gt;%
select(year, danceability, valence, energy) %&amp;gt;%
mutate(year = factor(year)) %&amp;gt;%
group_by(year) %&amp;gt;%
mutate(no = 1:n()) %&amp;gt;%
ungroup %&amp;gt;%
pivot_longer(c(danceability, valence, energy), names_to = &amp;#39;index&amp;#39;, values_to = &amp;#39;value&amp;#39;) %&amp;gt;%
mutate(dotx = case_when(year == &amp;#39;1960&amp;#39; ~ 1.15,
year == &amp;#39;2015&amp;#39; ~ 1.85),
vlinx = case_when(year == &amp;#39;1960&amp;#39; ~ 0.85,
year == &amp;#39;2015&amp;#39; ~ 2.15),
fill = case_when(year == &amp;#39;1960&amp;#39; &amp;amp; index == &amp;#39;danceability&amp;#39; ~ &amp;#39;#35999D&amp;#39;,
year == &amp;#39;1960&amp;#39; &amp;amp; index == &amp;#39;energy&amp;#39; ~ &amp;#39;#D0938B&amp;#39;,
year == &amp;#39;1960&amp;#39; &amp;amp; index == &amp;#39;valence&amp;#39; ~ &amp;#39;#D2B577&amp;#39;,
year == &amp;#39;2015&amp;#39; &amp;amp; index == &amp;#39;danceability&amp;#39; ~ &amp;#39;#356CA2&amp;#39;,
year == &amp;#39;2015&amp;#39; &amp;amp; index == &amp;#39;energy&amp;#39; ~ &amp;#39;#BA5555&amp;#39;,
year == &amp;#39;2015&amp;#39; &amp;amp; index == &amp;#39;valence&amp;#39; ~ &amp;#39;#BB683F&amp;#39;),
value = as.numeric(value))&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>#分别对三部分数据进行方差齐性检验并根据结果进行随后的差异t检验
#dance
data_dance &amp;lt;- compare[compare$fill == &amp;#39;#35999D&amp;#39;| compare$fill == &amp;#39;#356CA2&amp;#39;,]
leveneTest(data_dance$value,factor(data_dance$fill),center=mean)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>## Levene&amp;#39;s Test for Homogeneity of Variance (center = mean)
## Df F value Pr(&amp;gt;F)
## group 1 0.3261 0.5687
## 186&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>#energy
data_energy &amp;lt;- compare[compare$fill == &amp;#39;#D0938B&amp;#39;| compare$fill == &amp;#39;#BA5555&amp;#39;,]
leveneTest(data_energy$value,factor(data_energy$fill),center=mean)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>## Levene&amp;#39;s Test for Homogeneity of Variance (center = mean)
## Df F value Pr(&amp;gt;F)
## group 1 6.6239 0.01084 *
## 186
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>#valence
data_valence &amp;lt;- compare[compare$fill == &amp;#39;#D2B577&amp;#39;| compare$fill == &amp;#39;#BB683F&amp;#39;,]
leveneTest(data_valence$value,factor(data_valence$fill),center=mean)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>## Levene&amp;#39;s Test for Homogeneity of Variance (center = mean)
## Df F value Pr(&amp;gt;F)
## group 1 3.1566 0.07725 .
## 186
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>t.test(value ~ fill,data_dance, paired = F, var.equal = F)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>##
## Welch Two Sample t-test
##
## data: value by fill
## t = 5.1498, df = 185.72, p-value = 6.615e-07
## alternative hypothesis: true difference in means between group #356CA2 and group #35999D is not equal to 0
## 95 percent confidence interval:
## 0.06701662 0.15024701
## sample estimates:
## mean in group #356CA2 mean in group #35999D
## 0.6584318 0.5498000&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>t.test(value ~ fill,data_energy, paired = F, var.equal = T)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>##
## Two Sample t-test
##
## data: value by fill
## t = 10.39, df = 186, p-value &amp;lt; 2.2e-16
## alternative hypothesis: true difference in means between group #BA5555 and group #D0938B is not equal to 0
## 95 percent confidence interval:
## 0.1997677 0.2934115
## sample estimates:
## mean in group #BA5555 mean in group #D0938B
## 0.7039886 0.4573990&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>t.test(value ~ fill,data_valence, paired = F, var.equal = F)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>##
## Welch Two Sample t-test
##
## data: value by fill
## t = -3.8158, df = 185.98, p-value = 0.0001847
## alternative hypothesis: true difference in means between group #BB683F and group #D2B577 is not equal to 0
## 95 percent confidence interval:
## -0.20338511 -0.06475407
## sample estimates:
## mean in group #BB683F mean in group #D2B577
## 0.5388534 0.6729230&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code># 根据统计结果进行可视化展示
ggplot(compare, aes(y=value))+
geom_line(aes(x = dotx, group = no,fill = fill),
position = position_dodge(0.2),alpha = 0.35, color = &amp;#39;grey&amp;#39;)+
geom_point(aes(x = dotx, group = no,fill = fill),color = &amp;#39;white&amp;#39;,
position = position_dodge(0.2), shape = 21, size =2,alpha = 0.6)+
geom_half_violin(data = compare[compare$year == &amp;#39;1960&amp;#39;,],
aes(x = vlinx,fill = fill),
side = &amp;#39;l&amp;#39;,size = 0.3, trim = T,alpha = 0.8,color = &amp;#39;white&amp;#39;)+
geom_half_violin(data = compare[compare$year == &amp;#39;2015&amp;#39;,],
aes(x = vlinx,fill = fill),side = &amp;#39;r&amp;#39;,
size = 0.3, trim = T,alpha = 0.8,color = &amp;#39;white&amp;#39;)+
geom_boxplot(aes(x = vlinx, group = year), color = &amp;#39;white&amp;#39;, fill = &amp;#39;#B9C8E3&amp;#39;,
width = 0.2, size = 0.2, outlier.shape = NA,alpha = 0.5)+
stat_summary(aes(x = vlinx, color = fill), fun.data = &amp;quot;mean_cl_normal&amp;quot;,
fun.args = list(conf.int = .95), geom = &amp;#39;errorbar&amp;#39;,
width = 0.08,size = 0.5)+
geom_signif(data = data.frame(index = c(&amp;quot;danceability&amp;quot;,&amp;quot;energy&amp;quot;,&amp;#39;valence&amp;#39;)),
aes(annotations=rep(&amp;quot;***&amp;quot;, 3),
y_position=rep(1.05, 3), xmin=rep(0.8, 3), xmax=rep(2.2, 3)),
tip_length=0.02, manual = T,textsize = 8,vjust = 0.5) +
facet_grid(~index)+
scale_fill_identity()+
scale_color_identity()+
theme_prism(base_line_size =0.5)+
scale_x_continuous(expand = c(0,0),breaks = c(1,2),
labels = c(&amp;quot;1960&amp;quot;, &amp;quot;2015&amp;quot;),limits = c(0,3))+
labs(x = &amp;#39;Year&amp;#39;, y= &amp;#39;Score&amp;#39;, title = &amp;#39;1960 v.s. 2015&amp;#39;)+
theme(plot.margin = margin(2,2,2,2,unit = &amp;#39;mm&amp;#39;),
panel.grid.minor = element_line(size = 0.4,color = &amp;quot;#e5e5e5&amp;quot;),
panel.grid.major = element_line(size = 0.4,color = &amp;quot;#e5e5e5&amp;quot;),
panel.spacing = unit(0,&amp;quot;lines&amp;quot;),
axis.ticks = element_blank(),
plot.title = element_text(family = &amp;#39;kalam&amp;#39;, size =48),
axis.title = element_text(family = &amp;#39;kalam&amp;#39;, size =24),
axis.text = element_text(family = &amp;#39;mento&amp;#39;, size =24),
strip.text = element_text(family = &amp;#39;kalam&amp;#39;, size =32,vjust = 1)) -&amp;gt; compare_plot
ggsave(&amp;#39;wind&amp;amp;rain.png&amp;#39;,compare_plot,width=16,height = 8)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="wind&amp;amp;rain.png" />&lt;/p>
&lt;p>结果反应1960与2015间Top100歌曲在效价、能量值与舞动性均存在统计学意义上的&lt;strong>显著性差异&lt;/strong>，总体变化趋势与第三部分的结果一致。&lt;/p>
&lt;p>👋👋
以上就是本文的全部内容了，如果有什么建议欢迎联系我📱💌&lt;/p>
&lt;/div>
&lt;/div></description></item><item><title>购物App原型</title><link>https://www.wanghantong.site/portfolio/prototype/</link><pubDate>Sun, 20 Mar 2022 00:00:00 +0000</pubDate><guid>https://www.wanghantong.site/portfolio/prototype/</guid><description>&lt;p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis posuere tellus ac convallis placerat. Proin tincidunt magna sed ex sollicitudin condimentum. Sed ac faucibus dolor, scelerisque sollicitudin nisi. Cras purus urna, suscipit quis sapien eu, pulvinar tempor diam. Quisque risus orci, mollis id ante sit amet, gravida egestas nisl. Sed ac tempus magna. Proin in dui enim. Donec condimentum, sem id dapibus fringilla, tellus enim condimentum arcu, nec volutpat est felis vel metus. Vestibulum sit amet erat at nulla eleifend gravida.&lt;/p>
&lt;p>Nullam vel molestie justo. Curabitur vitae efficitur leo. In hac habitasse platea dictumst. Sed pulvinar mauris dui, eget varius purus congue ac. Nulla euismod, lorem vel elementum dapibus, nunc justo porta mi, sed tempus est est vel tellus. Nam et enim eleifend, laoreet sem sit amet, elementum sem. Morbi ut leo congue, maximus velit ut, finibus arcu. In et libero cursus, rutrum risus non, molestie leo. Nullam congue quam et volutpat malesuada. Sed risus tortor, pulvinar et dictum nec, sodales non mi. Phasellus lacinia commodo laoreet. Nam mollis, erat in feugiat consectetur, purus eros egestas tellus, in auctor urna odio at nibh. Mauris imperdiet nisi ac magna convallis, at rhoncus ligula cursus.&lt;/p>
&lt;p>Cras aliquam rhoncus ipsum, in hendrerit nunc mattis vitae. Duis vitae efficitur metus, ac tempus leo. Cras nec fringilla lacus. Quisque sit amet risus at ipsum pharetra commodo. Sed aliquam mauris at consequat eleifend. Praesent porta, augue sed viverra bibendum, neque ante euismod ante, in vehicula justo lorem ac eros. Suspendisse augue libero, venenatis eget tincidunt ut, malesuada at lorem. Donec vitae bibendum arcu. Aenean maximus nulla non pretium iaculis. Quisque imperdiet, nulla in pulvinar aliquet, velit quam ultrices quam, sit amet fringilla leo sem vel nunc. Mauris in lacinia lacus.&lt;/p>
&lt;p>Suspendisse a tincidunt lacus. Curabitur at urna sagittis, dictum ante sit amet, euismod magna. Sed rutrum massa id tortor commodo, vitae elementum turpis tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean purus turpis, venenatis a ullamcorper nec, tincidunt et massa. Integer posuere quam rutrum arcu vehicula imperdiet. Mauris ullamcorper quam vitae purus congue, quis euismod magna eleifend. Vestibulum semper vel augue eget tincidunt. Fusce eget justo sodales, dapibus odio eu, ultrices lorem. Duis condimentum lorem id eros commodo, in facilisis mauris scelerisque. Morbi sed auctor leo. Nullam volutpat a lacus quis pharetra. Nulla congue rutrum magna a ornare.&lt;/p>
&lt;p>Aliquam in turpis accumsan, malesuada nibh ut, hendrerit justo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque sed erat nec justo posuere suscipit. Donec ut efficitur arcu, in malesuada neque. Nunc dignissim nisl massa, id vulputate nunc pretium nec. Quisque eget urna in risus suscipit ultricies. Pellentesque odio odio, tincidunt in eleifend sed, posuere a diam. Nam gravida nisl convallis semper elementum. Morbi vitae felis faucibus, vulputate orci placerat, aliquet nisi. Aliquam erat volutpat. Maecenas sagittis pulvinar purus, sed porta quam laoreet at.&lt;/p></description></item></channel></rss>