{"id":826,"date":"2020-06-28T07:20:00","date_gmt":"2020-06-28T00:20:00","guid":{"rendered":"http:\/\/www.gis2me.com\/geospatial\/?p=826"},"modified":"2025-04-30T09:21:54","modified_gmt":"2025-04-30T02:21:54","slug":"r-studio-ep15-%e0%b8%88%e0%b8%b1%e0%b8%94%e0%b8%81%e0%b8%b2%e0%b8%a3-attribute-table-%e0%b8%82%e0%b9%89%e0%b8%ad%e0%b8%a1%e0%b8%b9%e0%b8%a5-covid-world-2020-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2","status":"publish","type":"post","link":"http:\/\/www.gis2me.com\/geospatial\/?p=826","title":{"rendered":"R-studio : ( EP#15 ) \u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Attribute Table \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 Covid World 2020 \u0e14\u0e49\u0e27\u0e22\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 R"},"content":{"rendered":"<p>R-studio : ( EP#15 ) \u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Attribute Table \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 Covid World 2020 \u0e14\u0e49\u0e27\u0e22\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 R<br \/><strong data-start=\"3\" data-end=\"12\">EP#15<\/strong> \u0e19\u0e35\u0e49 \u0e40\u0e23\u0e32\u0e08\u0e30\u0e40\u0e23\u0e35\u0e22\u0e19\u0e23\u0e39\u0e49\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 <strong data-start=\"40\" data-end=\"59\">Attribute Table<\/strong> \u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 <strong data-start=\"70\" data-end=\"93\">COVID-19 World 2020<\/strong> \u0e14\u0e49\u0e27\u0e22 <strong data-start=\"99\" data-end=\"112\">\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 R<\/strong> \u0e42\u0e14\u0e22\u0e21\u0e38\u0e48\u0e07\u0e40\u0e19\u0e49\u0e19\u0e17\u0e35\u0e48\u0e01\u0e32\u0e23\u0e17\u0e33\u0e04\u0e27\u0e32\u0e21\u0e2a\u0e30\u0e2d\u0e32\u0e14 (data cleaning), \u0e01\u0e32\u0e23\u0e23\u0e27\u0e21\u0e01\u0e25\u0e38\u0e48\u0e21 (aggregation), \u0e41\u0e25\u0e30\u0e01\u0e32\u0e23\u0e40\u0e15\u0e23\u0e35\u0e22\u0e21\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e01\u0e32\u0e23\u0e41\u0e2a\u0e14\u0e07\u0e1c\u0e25\u0e43\u0e19\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48 GIS \u0e2b\u0e23\u0e37\u0e2d Dashboard<\/p>\n<p>\u0e1f\u0e2d\u0e23\u0e4c\u0e21\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e02\u0e2d\u0e25\u0e34\u0e07\u0e04\u0e4c R script \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e1b\u0e0f\u0e34\u0e1a\u0e31\u0e15\u0e34\u0e01\u0e32\u0e23\u0e19\u0e35\u0e49 <a href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLSeEH__dM0amOxaWdkCkCsx9ocIRSDMXiL6RDGTHGHOHHkS1AQ\/viewform\">https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLSeEH__dM0amOxaWdkCkCsx9ocIRSDMXiL6RDGTHGHOHHkS1AQ\/viewform<\/a><\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/IgsdPJT_6A0\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udfaf \u0e27\u0e31\u0e15\u0e16\u0e38\u0e1b\u0e23\u0e30\u0e2a\u0e07\u0e04\u0e4c\u0e02\u0e2d\u0e07\u0e1a\u0e17\u0e40\u0e23\u0e35\u0e22\u0e19<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0e40\u0e23\u0e35\u0e22\u0e19\u0e23\u0e39\u0e49\u0e01\u0e32\u0e23\u0e19\u0e33\u0e40\u0e02\u0e49\u0e32 (import) \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 <code>.csv<\/code> \u0e08\u0e32\u0e01 GitHub\/Johns Hopkins<\/li>\n\n\n\n<li>\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 attribute table (date, country, cumulative case)<\/li>\n\n\n\n<li>\u0e2a\u0e23\u0e49\u0e32\u0e07 <code>tidy dataset<\/code> \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e01\u0e32\u0e23\u0e27\u0e34\u0e40\u0e04\u0e23\u0e32\u0e30\u0e2b\u0e4c\u0e2b\u0e23\u0e37\u0e2d\u0e41\u0e2a\u0e14\u0e07\u0e1c\u0e25\u0e1a\u0e19\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udce5 \u0e14\u0e32\u0e27\u0e19\u0e4c\u0e42\u0e2b\u0e25\u0e14 R Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd17 \u0e25\u0e07\u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e02\u0e2d\u0e23\u0e31\u0e1a R Markdown Script:<br><a class=\"\" href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLSeEH__dM0amOxaWdkCkCsx9ocIRSDMXiL6RDGTHGHOHHkS1AQ\/viewform\">\u0e41\u0e1a\u0e1a\u0e1f\u0e2d\u0e23\u0e4c\u0e21\u0e02\u0e2d\u0e25\u0e34\u0e07\u0e01\u0e4c R script \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a EP#15<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddf0 \u0e41\u0e1e\u0e47\u0e01\u0e40\u0e01\u0e08\u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e43\u0e19\u0e1a\u0e17\u0e40\u0e23\u0e35\u0e22\u0e19<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>install.packages(c(\"tidyverse\", \"lubridate\", \"sf\", \"janitor\"))\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e42\u0e2b\u0e25\u0e14\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 COVID-19<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>library(tidyverse)\nurl &lt;- \"https:\/\/raw.githubusercontent.com\/CSSEGISandData\/COVID-19\/master\/csse_covid_19_data\/csse_covid_19_time_series\/time_series_covid19_confirmed_global.csv\"\n\ncovid_data &lt;- read_csv(url)\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddf9 \u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Attribute Table<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>library(janitor)\n\ncovid_clean &lt;- covid_data %&gt;%\n  clean_names() %&gt;%\n  pivot_longer(cols = starts_with(\"x\"), names_to = \"date\", values_to = \"cases\") %&gt;%\n  mutate(\n    date = lubridate::mdy(str_remove(date, \"x\")),\n    country_region = as.factor(country_region)\n  )\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddee \u0e01\u0e32\u0e23\u0e23\u0e27\u0e21\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e32\u0e22\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28 \u0e23\u0e32\u0e22\u0e27\u0e31\u0e19<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>covid_daily &lt;- covid_clean %&gt;%\n  group_by(country_region, date) %&gt;%\n  summarise(total_cases = sum(cases, na.rm = TRUE), .groups = 'drop')\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udf0d \u0e01\u0e32\u0e23\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e01\u0e31\u0e1a\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28 (World shapefile)<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>library(sf)\n\nworld &lt;- st_read(\"path_to_world_shapefile.shp\") # \u0e2b\u0e23\u0e37\u0e2d\u0e43\u0e0a\u0e49 rnaturalearth\ncovid_map &lt;- world %&gt;%\n  left_join(covid_daily %&gt;% filter(date == as.Date(\"2020-04-01\")), by = c(\"NAME\" = \"country_region\"))\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udda5\ufe0f \u0e41\u0e2a\u0e14\u0e07\u0e1c\u0e25\u0e14\u0e49\u0e27\u0e22 ggplot2<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>ggplot(data = covid_map) +\n  geom_sf(aes(fill = total_cases)) +\n  scale_fill_viridis_c(option = \"plasma\") +\n  labs(title = \"Global COVID-19 Cases (Apr 1, 2020)\")\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\uddc2\ufe0f \u0e2a\u0e48\u0e07\u0e2d\u0e2d\u0e01\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 CSV \u0e2b\u0e23\u0e37\u0e2d GeoPackage<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>write_csv(covid_daily, \"covid_summary.csv\")\nst_write(covid_map, \"covid_world_map.gpkg\", delete_dsn = TRUE)\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc \u0e02\u0e49\u0e2d\u0e41\u0e19\u0e30\u0e19\u0e33\u0e40\u0e1e\u0e34\u0e48\u0e21\u0e40\u0e15\u0e34\u0e21<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0e04\u0e27\u0e23\u0e43\u0e0a\u0e49 <code>countrycode<\/code> package \u0e43\u0e19\u0e01\u0e23\u0e13\u0e35\u0e17\u0e35\u0e48\u0e0a\u0e37\u0e48\u0e2d\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28\u0e44\u0e21\u0e48\u0e15\u0e23\u0e07\u0e01\u0e31\u0e19 (normalize country names)<\/li>\n\n\n\n<li>\u0e1b\u0e23\u0e31\u0e1a\u0e42\u0e04\u0e23\u0e07\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e43\u0e2b\u0e49\u0e2d\u0e22\u0e39\u0e48\u0e43\u0e19\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a \u201clong format\u201d \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e43\u0e0a\u0e49\u0e01\u0e31\u0e1a Shiny, Leaflet, \u0e2b\u0e23\u0e37\u0e2d Dashboard<\/li>\n\n\n\n<li>\u0e17\u0e14\u0e25\u0e2d\u0e07\u0e43\u0e0a\u0e49 <code>plotly<\/code> \u0e2b\u0e23\u0e37\u0e2d <code>leaflet<\/code> \u0e41\u0e2a\u0e14\u0e07\u0e1c\u0e25\u0e41\u0e1a\u0e1a interactive<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>R-studio : ( EP#15 ) \u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Attribute Table \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 Covi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[484,499,494,495,451,440,502,493,497,501,439,486,500,496,498],"class_list":["post-826","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-attribute-table","tag-covid-mapping","tag-covid-19-data","tag-data-cleaning-r","tag-ggplot2-map","tag-gis--r","tag-global-health-gis","tag-janitor-r","tag-pivot_longer","tag-r-dashboard-preparation","tag-r-studio","tag-sf-package","tag-shapefile-covid","tag-tidyverse","tag-world-map-r"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/posts\/826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=826"}],"version-history":[{"count":1,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/posts\/826\/revisions"}],"predecessor-version":[{"id":827,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/posts\/826\/revisions\/827"}],"wp:attachment":[{"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=826"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}