<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>对比 on 格物堂</title><link>https://gewutang.cn/tags/%E5%AF%B9%E6%AF%94/</link><description>Recent content in 对比 on 格物堂</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Sat, 12 Feb 2011 00:00:00 +0000</lastBuildDate><atom:link href="https://gewutang.cn/tags/%E5%AF%B9%E6%AF%94/index.xml" rel="self" type="application/rss+xml"/><item><title>2010年中国与美国经济对比</title><link>https://gewutang.cn/2011/02/12/china-vs-usa/</link><pubDate>Sat, 12 Feb 2011 00:00:00 +0000</pubDate><guid>https://gewutang.cn/2011/02/12/china-vs-usa/</guid><description>&lt;p&gt;中国和美国现在的实力越来越接近，也许在未来会发生很多微妙的事情。对于这个实际而言，有两个实力接近的国家历来不是什么好事。&lt;/p&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;library(WDI)&#10;library(tidyverse)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──&#10;## ✔ dplyr 1.1.4 ✔ readr 2.1.5&#10;## ✔ forcats 1.0.0 ✔ stringr 1.5.1&#10;## ✔ ggplot2 3.5.2 ✔ tibble 3.2.1&#10;## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1&#10;## ✔ purrr 1.0.4 &#10;## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──&#10;## ✖ dplyr::filter() masks stats::filter()&#10;## ✖ dplyr::lag() masks stats::lag()&#10;## ℹ Use the conflicted package (&amp;lt;http://conflicted.r-lib.org/&amp;gt;) to force all conflicts to become errors&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;library(plotly)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## 载入程序包：'plotly'&#10;## &#10;## The following object is masked from 'package:ggplot2':&#10;## &#10;## last_plot&#10;## &#10;## The following object is masked from 'package:stats':&#10;## &#10;## filter&#10;## &#10;## The following object is masked from 'package:graphics':&#10;## &#10;## layout&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;library(dplyr)&#10;library(ggplot2)&#10;&#10;# 获取GDP数据（当前美元价）&#10;gdp_data &amp;lt;- WDI(&#10; country = c(&amp;quot;CN&amp;quot;, &amp;quot;US&amp;quot;),&#10; indicator = c(&amp;quot;NY.GDP.MKTP.CD&amp;quot;, &amp;quot;NY.GDP.PCAP.CD&amp;quot;), # GDP总量与人均GDP&#10; start = 1978,&#10; end = 2010&#10;) %&amp;gt;%&#10; rename(gdp = NY.GDP.MKTP.CD, gdp_per_cap = NY.GDP.PCAP.CD) %&amp;gt;%&#10; mutate(country = case_when(&#10; iso2c == &amp;quot;CN&amp;quot; ~ &amp;quot;中国&amp;quot;,&#10; iso2c == &amp;quot;US&amp;quot; ~ &amp;quot;美国&amp;quot;&#10; ))&#10; &#10; &#10; p1 &amp;lt;- ggplot(gdp_data, aes(x=year, y=gdp/1e12, color=country)) +&#10; geom_line(linewidth=1.2) +&#10; scale_y_log10(&#10; &amp;quot;GDP（万亿美元）&amp;quot;,&#10; breaks = c(0.1, 1, 10),&#10; labels = c(&amp;quot;0.1&amp;quot;, &amp;quot;1&amp;quot;, &amp;quot;10&amp;quot;)&#10; ) +&#10; scale_color_manual(values=c(&amp;quot;#D62728&amp;quot;, &amp;quot;#2CA02C&amp;quot;)) +&#10; labs(title=&amp;quot;1978-2010中美GDP增长轨迹对比&amp;quot;,&#10; subtitle=&amp;quot;数据来源：世界银行WDI数据库（经对数转换处理）&amp;quot;) +&#10; theme_minimal(base_family=&amp;quot;PingFang SC&amp;quot;)&#10; p1&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/02/12/china-vs-usa/index_files/figure-html/unnamed-chunk-1-1.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt; # 保存为pdf文件&#10; # ggsave(&amp;quot;Sino-US_gdp.pdf&amp;quot;, device=cairo_pdf, width=14, height=9, dpi=300)&#10; # 转化为交互图形&#10; # ggplotly(p1)&#10; &#10; gdp_data &amp;lt;- WDI(&#10; country = c(&amp;quot;CN&amp;quot;, &amp;quot;US&amp;quot;),&#10; indicator = c(&amp;quot;NY.GDP.MKTP.CD&amp;quot;, &amp;quot;NY.GDP.PCAP.CD&amp;quot;), &#10; start = 1978,&#10; end = 2010&#10;) %&amp;gt;%&#10; rename(gdp = NY.GDP.MKTP.CD, gdp_per_cap = NY.GDP.PCAP.CD) %&amp;gt;%&#10; mutate(global_share = gdp / sum(gdp)) %&amp;gt;%&#10; group_by(year) &#10; p2 &amp;lt;- ggplot(gdp_data, aes(x=year, y=global_share, fill=country)) +&#10; geom_area(alpha=0.8) +&#10; scale_y_continuous(labels=scales::percent) +&#10; labs(y=&amp;quot;占全球GDP比重&amp;quot;, title=&amp;quot;全球经济格局演变&amp;quot;)&#10; p2&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/02/12/china-vs-usa/index_files/figure-html/unnamed-chunk-1-2.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt; # 保存为pdf文件&#10; # ggsave(&amp;quot;Sino-US_Comparison.pdf&amp;quot;, device=cairo_pdf, width=14, height=9, dpi=300)&#10; # 转化为交互图表&#10; # ggplotly(p2) &#10;&lt;/code&gt;&lt;/pre&gt;&#10;</description></item></channel></rss>