如何从面板/纵向数据中选择一年以图表形式显示?

如何解决如何从面板/纵向数据中选择一年以图表形式显示?

我为167个国家/地区以及2009-2017年提供了以下数据集。 head(df)如下:

area_code year   area_name   area_group Executive Constraints Government Effectiveness Government Integrity
1       AFG 2009 Afghanistan Asia-Pacific              5.940404                 5.601888             5.817723
2       AFG 2010 Afghanistan Asia-Pacific              5.940404                 5.614891             5.817723
3       AFG 2011 Afghanistan Asia-Pacific              5.940404                 4.164573             6.077723
4       AFG 2012 Afghanistan Asia-Pacific              5.940404                 4.171181             6.077723
5       AFG 2013 Afghanistan Asia-Pacific              5.940404                 4.265419             6.837723
6       AFG 2014 Afghanistan Asia-Pacific              5.940404                 4.238977             6.837723
  Political Accountability Regulatory Quality Rule of Law Contract Enforcement Investor Protection
1                 3.852381           4.622449    5.684202             4.211907            4.514932
2                 3.495238           4.582903    5.684202             4.211907            4.514932
3                 3.495238           4.688990    5.684202             4.211907            4.612633
4                 3.495238           4.683196    5.684202             4.211907            4.641368
5                 3.495238           4.943797    5.684202             4.211907            4.635621
6                 4.780952           4.943783    5.684202             4.211907            4.641368
  Property Rights  Val.Avg   HDI     LE                   Subject Descriptor          Units Scale
1        8.746632 5.443613 0.453 60.484 General government total expenditure Percent of GDP    NA
2        9.032347 5.432727 0.463 61.028 General government total expenditure Percent of GDP    NA
3        8.937204 5.312542 0.471 61.553 General government total expenditure Percent of GDP    NA
4        8.937204 5.315825 0.482 62.054 General government total expenditure Percent of GDP    NA
5        8.937204 5.439057 0.487 62.525 General government total expenditure Percent of GDP    NA
6        8.937204 5.579613 0.491 62.966 General government total expenditure Percent of GDP    NA
                                              Country/Series-specific Notes Estimates Start After
1 See notes for:  General government total expenditure (National currency).                  2018
2 See notes for:  General government total expenditure (National currency).                  2018
3 See notes for:  General government total expenditure (National currency).                  2018
4 See notes for:  General government total expenditure (National currency).                  2018
5 See notes for:  General government total expenditure (National currency).                  2018
6 See notes for:  General government total expenditure (National currency).                  2018
             e_p_GDP
1              21.17
2 20.800999999999998
3 21.937000000000001
4 25.027999999999999
5             24.977
6 25.402000000000001

我想知道如何仅绘制给定年份或国家的数据? 例如。在2009年至2017年期间某个国家(例如阿富汗)的某个变量(例如HDI)的散点图,或在一年中(例如2017年)所有国家的一些变量的散点图。

这是dput(head(df)):

structure(list(area_code = c("AFG","AFG","AFG"),year = c("2009","2010","2011","2012","2013","2014"
),area_name = c("Afghanistan","Afghanistan","Afghanistan"),area_group = c("Asia-Pacific","Asia-Pacific","Asia-Pacific"),`Executive Constraints` = c(5.9404040404,5.9404040404,5.9404040404),`Government Effectiveness` = c(5.6018883995,5.6148910662,4.164573318,4.171181318,4.2654191847,4.238976518
),`Government Integrity` = c(5.8177230501,5.8177230501,6.0777230501,6.8377230501,6.8377230501),`Political Accountability` = c(3.8523809524,3.4952380952,4.780952381
),`Regulatory Quality` = c(4.6224485009,4.5829025009,4.6889900009,4.6831962509,4.9437972509,4.9437830009),`Rule of Law` = c(5.684202383,5.684202383,5.684202383
),`Contract Enforcement` = c(4.2119071093,4.2119071093,4.2119071093),`Investor Protection` = c(4.5149315168,4.5149315168,4.6126326662,4.6413682984,4.6356211719,4.6413682984
),`Property Rights` = c(8.7466324809,9.0323467666,8.9372039095,8.9372039095),Val.Avg = c(5.44361315925556,5.43272739205556,5.31254161917778,5.31582493942222,5.439057355,5.57961341006667),HDI = c(0.453,0.463,0.471,0.482,0.487,0.491),LE = c(60.484,61.028,61.553,62.054,62.525,62.966
),`Subject Descriptor` = c("General government total expenditure","General government total expenditure","General government total expenditure"),Units = c("Percent of GDP","Percent of GDP","Percent of GDP"),Scale = c(NA,NA,NA),`Country/Series-specific Notes` = c("See notes for:  General government total expenditure (National currency).","See notes for:  General government total expenditure (National currency).","See notes for:  General government total expenditure (National currency)."
),`Estimates Start After` = c(2018,2018,2018),e_p_GDP = c("21.17","20.800999999999998","21.937000000000001","25.027999999999999","24.977","25.402000000000001")),row.names = c(NA,6L),class = "data.frame")

解决方法

选择要绘制的数据子集

ggplot(subset(df,year==2019 & area_name=="Denmark"),aes(HDI,LE)) + 
geom_point()

或全部绘制:

ggplot(df,LE)) + 
geom_point() +
facet_grid(year~area_name)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-