{"id":830,"date":"2020-07-18T07:26:00","date_gmt":"2020-07-18T00:26:00","guid":{"rendered":"http:\/\/www.gis2me.com\/geospatial\/?p=830"},"modified":"2025-04-30T09:20:27","modified_gmt":"2025-04-30T02:20:27","slug":"r-studio-ep17-%e0%b9%81%e0%b8%aa%e0%b8%94%e0%b8%87%e0%b9%81%e0%b8%9c%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-thailand-map-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2%e0%b8%82%e0%b9%89%e0%b8%ad%e0%b8%a1","status":"publish","type":"post","link":"http:\/\/www.gis2me.com\/geospatial\/?p=830","title":{"rendered":"R-studio : ( EP#17 ) \u0e41\u0e2a\u0e14\u0e07\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48 Thailand Map \u0e14\u0e49\u0e27\u0e22\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49 Income \u0e14\u0e49\u0e27\u0e22\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 R \u0e41\u0e25\u0e30 Excel \u0e23\u0e48\u0e27\u0e21\u0e01\u0e31\u0e1a Shapefile"},"content":{"rendered":"<p>R-studio : ( EP#17 )\u00a0 \u0e41\u0e2a\u0e14\u0e07\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48 Thailand Map \u0e14\u0e49\u0e27\u0e22\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49 Income \u0e14\u0e49\u0e27\u0e22\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 R \u0e41\u0e25\u0e30 Excel \u0e23\u0e48\u0e27\u0e21\u0e01\u0e31\u0e1a Shapefile<\/p>\n<p>\u0e40\u0e1b\u0e47\u0e19\u0e01\u0e32\u0e23\u0e1d\u0e36\u0e01\u0e1b\u0e0f\u0e34\u0e1a\u0e31\u0e15\u0e34\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 Excel \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49\u0e1b\u0e23\u0e30\u0e0a\u0e32\u0e01\u0e23\u0e23\u0e32\u0e22\u0e04\u0e23\u0e31\u0e27\u0e40\u0e23\u0e37\u0e2d\u0e19\u0e02\u0e2d\u0e07\u0e41\u0e15\u0e48\u0e25\u0e30\u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14 \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e19\u0e33\u0e21\u0e32\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e42\u0e22\u0e07\u0e01\u0e31\u0e1a Shapefile \u0e23\u0e32\u0e22\u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14 \u0e43\u0e19\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 R<\/p>\n<p>\u0e25\u0e07\u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e02\u0e2d\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e44\u0e1f\u0e25\u0e4c R script \u0e44\u0e14\u0e49\u0e17\u0e35\u0e48<br \/>\n<a href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLScmTzGffy6O51V-E32XN0TMDQHE_I6tJQMn9Rj-G2dVn2pC2g\/viewform\">https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLScmTzGffy6O51V-E32XN0TMDQHE_I6tJQMn9Rj-G2dVn2pC2g\/viewform<\/a><\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/Z-jtunaMFvc\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n\n<h3 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<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u0e1a\u0e17\u0e40\u0e23\u0e35\u0e22\u0e19\u0e19\u0e35\u0e49\u0e2d\u0e2d\u0e01\u0e41\u0e1a\u0e1a\u0e21\u0e32\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e43\u0e2b\u0e49\u0e1c\u0e39\u0e49\u0e40\u0e23\u0e35\u0e22\u0e19:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0e43\u0e0a\u0e49\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21 <strong>R<\/strong> \u0e23\u0e48\u0e27\u0e21\u0e01\u0e31\u0e1a <strong>Excel<\/strong> \u0e41\u0e25\u0e30 <strong>Shapefile<\/strong> \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e01\u0e32\u0e23\u0e41\u0e2a\u0e14\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49\u0e02\u0e2d\u0e07\u0e41\u0e15\u0e48\u0e25\u0e30\u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14\u0e43\u0e19\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48<\/li>\n\n\n\n<li>\u0e40\u0e23\u0e35\u0e22\u0e19\u0e23\u0e39\u0e49\u0e01\u0e32\u0e23 <strong>\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e42\u0e22\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e15\u0e32\u0e23\u0e32\u0e07 (Join)<\/strong> \u0e08\u0e32\u0e01 Excel \u0e01\u0e31\u0e1a\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e1e\u0e37\u0e49\u0e19\u0e17\u0e35\u0e48 (Polygon) \u0e08\u0e32\u0e01 Shapefile<\/li>\n\n\n\n<li>\u0e2a\u0e23\u0e49\u0e32\u0e07 <strong>\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48\u0e40\u0e0a\u0e34\u0e07\u0e1b\u0e23\u0e34\u0e21\u0e32\u0e13 (Choropleth Map)<\/strong> \u0e14\u0e49\u0e27\u0e22\u0e41\u0e1e\u0e47\u0e01\u0e40\u0e01\u0e08 <code>leaflet<\/code> \u0e2b\u0e23\u0e37\u0e2d <code>ggplot2<\/code> \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e41\u0e2a\u0e14\u0e07\u0e23\u0e30\u0e14\u0e31\u0e1a\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\uddc2\ufe0f \u0e42\u0e04\u0e23\u0e07\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14<\/th><th>income_avg<\/th><\/tr><\/thead><tbody><tr><td>\u0e01\u0e23\u0e38\u0e07\u0e40\u0e17\u0e1e\u0e21\u0e2b\u0e32\u0e19\u0e04\u0e23<\/td><td>25,000<\/td><\/tr><tr><td>\u0e40\u0e0a\u0e35\u0e22\u0e07\u0e43\u0e2b\u0e21\u0e48<\/td><td>19,000<\/td><\/tr><tr><td>\u0e19\u0e04\u0e23\u0e23\u0e32\u0e0a\u0e2a\u0e35\u0e21\u0e32<\/td><td>15,800<\/td><\/tr><tr><td>&#8230;<\/td><td>&#8230;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Excel<\/strong>: \u0e21\u0e35\u0e04\u0e2d\u0e25\u0e31\u0e21\u0e19\u0e4c <code>province_name<\/code> \u0e41\u0e25\u0e30 <code>income_avg<\/code><\/li>\n\n\n\n<li><strong>Shapefile<\/strong>: Polygon \u0e02\u0e2d\u0e07\u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14 \u0e42\u0e14\u0e22\u0e0a\u0e37\u0e48\u0e2d\u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14\u0e43\u0e19 <code>.shp<\/code> \u0e15\u0e49\u0e2d\u0e07\u0e15\u0e23\u0e07\u0e01\u0e31\u0e1a Excel (<code>province_name<\/code>)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83e\uddf0 \u0e41\u0e1e\u0e47\u0e01\u0e40\u0e01\u0e08\u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e43\u0e19 R<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>install.packages(c(\"sf\", \"readxl\", \"leaflet\", \"dplyr\", \"RColorBrewer\"))\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcdc \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 R Script \u0e40\u0e1a\u0e37\u0e49\u0e2d\u0e07\u0e15\u0e49\u0e19<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">rCopyEdit<code>library(sf)\nlibrary(readxl)\nlibrary(leaflet)\nlibrary(dplyr)\nlibrary(RColorBrewer)\n\n# \u0e2d\u0e48\u0e32\u0e19 shapefile \u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14\nthai_prov &lt;- st_read(\"thailand_province.shp\")\n\n# \u0e2d\u0e48\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49\u0e08\u0e32\u0e01 Excel\nincome_data &lt;- read_excel(\"income_by_province.xlsx\")\n\n# \u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\nthai_income &lt;- thai_prov %&gt;%\n  left_join(income_data, by = c(\"province_name\" = \"province_name\"))\n\n# \u0e2a\u0e23\u0e49\u0e32\u0e07 color palette\npal &lt;- colorNumeric(palette = \"YlOrRd\", domain = thai_income$income_avg)\n\n# \u0e41\u0e2a\u0e14\u0e07\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48\nleaflet(thai_income) %&gt;%\n  addTiles() %&gt;%\n  addPolygons(\n    fillColor = ~pal(income_avg),\n    fillOpacity = 0.7,\n    color = \"#333333\",\n    weight = 1,\n    label = ~paste(province_name, \"&lt;br&gt;\", \"\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49\u0e40\u0e09\u0e25\u0e35\u0e48\u0e22: \", income_avg, \"\u0e1a\u0e32\u0e17\")\n  ) %&gt;%\n  addLegend(pal = pal, values = ~income_avg, title = \"\u0e23\u0e32\u0e22\u0e44\u0e14\u0e49\u0e40\u0e09\u0e25\u0e35\u0e48\u0e22\")\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udce5 \u0e25\u0e07\u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e02\u0e2d\u0e23\u0e31\u0e1a R script \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udc49 <a class=\"\" href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLScmTzGffy6O51V-E32XN0TMDQHE_I6tJQMn9Rj-G2dVn2pC2g\/viewform\">Google Form \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e02\u0e2d\u0e44\u0e1f\u0e25\u0e4c\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 R script \u0e41\u0e25\u0e30 Excel<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udca1 \u0e40\u0e04\u0e25\u0e47\u0e14\u0e25\u0e31\u0e1a\u0e40\u0e1e\u0e34\u0e48\u0e21\u0e40\u0e15\u0e34\u0e21<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0e43\u0e0a\u0e49 <code>View()<\/code> \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e15\u0e23\u0e27\u0e08\u0e2a\u0e2d\u0e1a\u0e0a\u0e37\u0e48\u0e2d\u0e04\u0e2d\u0e25\u0e31\u0e21\u0e19\u0e4c\u0e43\u0e2b\u0e49\u0e15\u0e23\u0e07\u0e01\u0e31\u0e19\u0e01\u0e48\u0e2d\u0e19\u0e17\u0e33 <code>join<\/code><\/li>\n\n\n\n<li>\u0e01\u0e23\u0e13\u0e35\u0e0a\u0e37\u0e48\u0e2d\u0e08\u0e31\u0e07\u0e2b\u0e27\u0e31\u0e14\u0e44\u0e21\u0e48\u0e15\u0e23\u0e07 \u0e43\u0e2b\u0e49\u0e43\u0e0a\u0e49 <code>stringr::str_trim()<\/code> \u0e2b\u0e23\u0e37\u0e2d <code>iconv()<\/code> \u0e0a\u0e48\u0e27\u0e22\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 encoding<\/li>\n\n\n\n<li>\u0e2b\u0e32\u0e01\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23 export \u0e40\u0e1b\u0e47\u0e19 HTML: \u0e43\u0e0a\u0e49 <code>htmlwidgets::saveWidget()<\/code> \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e44\u0e1f\u0e25\u0e4c\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48\u0e2a\u0e48\u0e07\u0e07\u0e32\u0e19<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>R-studio : ( EP#17 )\u00a0 \u0e41\u0e2a\u0e14\u0e07\u0e41\u0e1c\u0e19\u0e17\u0e35\u0e48 Thailand Map \u0e14\u0e49\u0e27\u0e22\u0e02\u0e49\u0e2d\u0e21\u0e39 [&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":[21],"tags":[465,462,476,451,440,467,477,439,475,478,474,479,470,481,480],"class_list":["post-830","post","type-post","status-publish","format-standard","hentry","category--r-studio","tag-choropleth-map","tag-data-visualization-r","tag-excel-join-shapefile","tag-ggplot2-map","tag-gis--r","tag-income-mapping","tag-leaflet-r","tag-r-studio","tag-r--gis","tag-readxl","tag-shapefile-","tag-spatial-join-r","tag-thailand-income-map","tag-481","tag-480"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/posts\/830","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=830"}],"version-history":[{"count":1,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/posts\/830\/revisions"}],"predecessor-version":[{"id":831,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=\/wp\/v2\/posts\/830\/revisions\/831"}],"wp:attachment":[{"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=830"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gis2me.com\/geospatial\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}