<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Epidemiology | Tengku Hanis</title>
    <link>https://tengkuhanis.netlify.app/category/epidemiology/</link>
      <atom:link href="https://tengkuhanis.netlify.app/category/epidemiology/index.xml" rel="self" type="application/rss+xml" />
    <description>Epidemiology</description>
    <generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><copyright>©Tengku Hanis 2020-2025 Made with [blogdown](https://github.com/rstudio/blogdown)</copyright><lastBuildDate>Wed, 22 Feb 2023 00:00:00 +0000</lastBuildDate>
    <image>
      <url>https://tengkuhanis.netlify.app/images/icon_hua2ec155b4296a9c9791d015323e16eb5_11927_512x512_fill_lanczos_center_2.png</url>
      <title>Epidemiology</title>
      <link>https://tengkuhanis.netlify.app/category/epidemiology/</link>
    </image>
    
    <item>
      <title>Mapping the states in Malaysia</title>
      <link>https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/</link>
      <pubDate>Wed, 22 Feb 2023 00:00:00 +0000</pubDate>
      <guid>https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/</guid>
      <description>


&lt;p&gt;I have written two blog posts about making map in R:&lt;/p&gt;
&lt;ol style=&#34;list-style-type: decimal&#34;&gt;
&lt;li&gt;&lt;a href=&#34;https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/&#34;&gt;Making maps with R (my first attempt ever!)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://tengkuhanis.netlify.app/post/my-first-interactive-map-with-leaflet/&#34;&gt;My first interactive map with {leaflet}&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This post is sort of a continuation to the &lt;a href=&#34;https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/&#34;&gt;first blog post&lt;/a&gt;. I have shown how to plot a coordinate to a map in that post specifically for Malaysia.&lt;/p&gt;
&lt;p&gt;However, using the two approaches in the previous blog post, we cannot plot the coordinate to a certain states in Malaysia. At least I am not unable to find how to do that after googling around. But, we can plot the borneo or peninsular of Malaysia using the two approaches.&lt;/p&gt;
&lt;div id=&#34;plot-the-peninsular-of-malaysia-not-the-best-way&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Plot the peninsular of Malaysia (not the best way)&lt;/h2&gt;
&lt;p&gt;Load the necessary packages.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(rworldmap) 
library(tidyverse)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First, we get the data. The data is about desa clinic (klinik desa) in Malaysia.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;clinicDesa &amp;lt;- read.csv(&amp;quot;https://raw.githubusercontent.com/tengku-hanis/clinic-data/main/clinicdesa.csv&amp;quot;)
head(clinicDesa)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##   id facilities_id                     name              address postcode
## 1  1    KD01010019  KLINIK DESA ASSAM BUBOK     Jalan Batu Pahat    86400
## 2  2    KD01010020   KLINIK DESA BATU PUTIH    Jalan Behor Temak    83000
## 3  3    KD01010021      KLINIK DESA BEROLEH    Jalan Parit Besar    83300
## 4  4    KD01010022        KLINIK DESA BINDU Jalan Tongkang Pecah    83010
## 5  5    KD01010023 KLINIK DESA KAMPUNG BARU   Jalan Parit Kemang    83710
## 6  6    KD01010024 KLINIK DESA KANGKAR BARU      Jalan Meng Seng    85400
##             city   district  state tel fax website email image latitude
## 1     Ayer Hitam Batu Pahat Johor       NA      NA    NA    NA 1.933330
## 2          Bagan Batu Pahat Johor       NA      NA    NA    NA 1.889100
## 3     Sri Gading Batu Pahat Johor       NA      NA    NA    NA 1.877890
## 4 Tongkang Pecah Batu Pahat Johor       NA      NA    NA    NA 1.901515
## 5    Parit Yaani Batu Pahat Johor       NA      NA    NA    NA 1.905120
## 6      Yong Peng Batu Pahat Johor       NA      NA    NA    NA 2.065310
##   longitude likes rating status
## 1  103.1167     0      0    NEW
## 2  102.8778     0      0    NEW
## 3  102.9858     0      0    NEW
## 4  102.9665     0      0    NEW
## 5  103.0372     0      0    NEW
## 6  103.1248     0      0    NEW&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First we plot the data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot(clinicDesa, aes(longitude, latitude)) +
  geom_point() +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-3-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Remove the two points.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;clinicDesa2 &amp;lt;- clinicDesa %&amp;gt;% filter(longitude &amp;gt; 25)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, plot the updated data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot(clinicDesa2, aes(longitude, latitude)) +
  geom_point() +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-5-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;From the plot, we already know the left side consists of the coordinates in the peninsular of Malaysia. So, we can limit our plot by limit the longitude &amp;lt; 105 and longitude &amp;gt; 97.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Get base map
global &amp;lt;- map_data(&amp;quot;world&amp;quot;) 

# Plot
ggplot() + 
  geom_polygon(data = global %&amp;gt;% filter(region == &amp;quot;Malaysia&amp;quot;), aes(x=long, y = lat, group = group), 
               fill = &amp;quot;gray85&amp;quot;) + 
  coord_fixed(1.3) +
  geom_point(data = clinicDesa2, aes(x = longitude, y = latitude)) +
  theme_minimal() + 
  xlab(&amp;quot;Longitude&amp;quot;) +
  ylab(&amp;quot;Latitude&amp;quot;) +
  labs(title = &amp;quot;Desa clinic in the peninsular of Malaysia&amp;quot;, 
       subtitle = &amp;quot;(Data last updated: Klinik Desa - 9 Mac 2021)&amp;quot;,
       caption = expression(paste(italic(&amp;quot;Sumber data: https://www.data.gov.my/data/ms_MY/group/pemetaan&amp;quot;)))) +
  xlim(97, 105) #limit overall map to peninsular of Malaysia&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-6-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;I am not going to re-explain the above and below codes as I have explain it in &lt;a href=&#34;https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/&#34;&gt;the previous blog post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This approach also works with &lt;code&gt;rworldmap&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Get base map
world &amp;lt;- getMap(resolution = &amp;quot;low&amp;quot;)
msia &amp;lt;- world[world@data$ADMIN == &amp;quot;Malaysia&amp;quot;, ]

# Plot
ggplot() +
  geom_polygon(data = msia, aes(x = long, y = lat, group = group), fill = NA, colour = &amp;quot;black&amp;quot;) +
  geom_point(data = clinicDesa2, aes(x = longitude, y = latitude)) +
  coord_quickmap() + 
  theme_minimal() + 
  xlab(&amp;quot;Longitude&amp;quot;) +
  ylab(&amp;quot;Latitude&amp;quot;) +
  labs(title = &amp;quot;Desa clinic in the peninsular of Malaysia&amp;quot;, 
       subtitle = &amp;quot;(Data last updated: Klinik Desa - 9 Mac 2021)&amp;quot;,
       caption = expression(paste(italic(&amp;quot;Sumber data: https://www.data.gov.my/data/ms_MY/group/pemetaan&amp;quot;)))) +
  xlim(97, 105) #limit overall map to peninsular of Malaysia&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-7-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;As we can see using the two approaches, we can plot the borne and peninsular sides of Malaysia. But, at least to my knowledge we cannot apply this approach if we want to plot a coordinate to certain states in Malaysia.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;plot-the-states-in-malaysia&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Plot the states in Malaysia&lt;/h2&gt;
&lt;p&gt;Load the necessary package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(geodata)
library(tidyterra)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As we can see from the package, we going to use a &lt;code&gt;geodata&lt;/code&gt; package. &lt;code&gt;tidyterra&lt;/code&gt; is used to supplements the ggplot. First, let’s limit the data into desa clinics in Terengganu only.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;clinic_trg &amp;lt;- 
  clinicDesa %&amp;gt;% 
  filter(state == &amp;quot;Terengganu&amp;quot;) %&amp;gt;% 
  dplyr::select(latitude, longitude) 
head(clinic_trg)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##   latitude longitude
## 1  5.48533  102.4914
## 2  5.81578  102.5778
## 3  5.70886  102.4892
## 4  5.75722  102.5303
## 5  5.67444  102.6289
## 6  5.69875  102.5430&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we get the map from the &lt;code&gt;geodata&lt;/code&gt; package with the boundaries at the district level.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;Malaysia &amp;lt;- gadm(country = &amp;quot;MYS&amp;quot;, level = 2, path=tempdir())&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can use the below information to limit the map to Terengganu state only.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;Malaysia$NAME_1&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##   [1] &amp;quot;Johor&amp;quot;           &amp;quot;Johor&amp;quot;           &amp;quot;Johor&amp;quot;           &amp;quot;Johor&amp;quot;          
##   [5] &amp;quot;Johor&amp;quot;           &amp;quot;Johor&amp;quot;           &amp;quot;Johor&amp;quot;           &amp;quot;Johor&amp;quot;          
##   [9] &amp;quot;Johor&amp;quot;           &amp;quot;Johor&amp;quot;           &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;          
##  [13] &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;          
##  [17] &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;          
##  [21] &amp;quot;Kedah&amp;quot;           &amp;quot;Kedah&amp;quot;           &amp;quot;Kelantan&amp;quot;        &amp;quot;Kelantan&amp;quot;       
##  [25] &amp;quot;Kelantan&amp;quot;        &amp;quot;Kelantan&amp;quot;        &amp;quot;Kelantan&amp;quot;        &amp;quot;Kelantan&amp;quot;       
##  [29] &amp;quot;Kelantan&amp;quot;        &amp;quot;Kelantan&amp;quot;        &amp;quot;Kelantan&amp;quot;        &amp;quot;Kelantan&amp;quot;       
##  [33] &amp;quot;Kuala Lumpur&amp;quot;    &amp;quot;Labuan&amp;quot;          &amp;quot;Melaka&amp;quot;          &amp;quot;Melaka&amp;quot;         
##  [37] &amp;quot;Melaka&amp;quot;          &amp;quot;Negeri Sembilan&amp;quot; &amp;quot;Negeri Sembilan&amp;quot; &amp;quot;Negeri Sembilan&amp;quot;
##  [41] &amp;quot;Negeri Sembilan&amp;quot; &amp;quot;Negeri Sembilan&amp;quot; &amp;quot;Negeri Sembilan&amp;quot; &amp;quot;Negeri Sembilan&amp;quot;
##  [45] &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;         
##  [49] &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;         
##  [53] &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;          &amp;quot;Pahang&amp;quot;          &amp;quot;Perak&amp;quot;          
##  [57] &amp;quot;Perak&amp;quot;           &amp;quot;Perak&amp;quot;           &amp;quot;Perak&amp;quot;           &amp;quot;Perak&amp;quot;          
##  [61] &amp;quot;Perak&amp;quot;           &amp;quot;Perak&amp;quot;           &amp;quot;Perak&amp;quot;           &amp;quot;Perak&amp;quot;          
##  [65] &amp;quot;Perak&amp;quot;           &amp;quot;Perlis&amp;quot;          &amp;quot;Pulau Pinang&amp;quot;    &amp;quot;Pulau Pinang&amp;quot;   
##  [69] &amp;quot;Pulau Pinang&amp;quot;    &amp;quot;Pulau Pinang&amp;quot;    &amp;quot;Pulau Pinang&amp;quot;    &amp;quot;Putrajaya&amp;quot;      
##  [73] &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;          
##  [77] &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;          
##  [81] &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;          
##  [85] &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;          
##  [89] &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;          
##  [93] &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;           &amp;quot;Sabah&amp;quot;          
##  [97] &amp;quot;Sabah&amp;quot;           &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [101] &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [105] &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [109] &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [113] &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [117] &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [121] &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [125] &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;         &amp;quot;Sarawak&amp;quot;        
## [129] &amp;quot;Selangor&amp;quot;        &amp;quot;Selangor&amp;quot;        &amp;quot;Selangor&amp;quot;        &amp;quot;Selangor&amp;quot;       
## [133] &amp;quot;Selangor&amp;quot;        &amp;quot;Selangor&amp;quot;        &amp;quot;Selangor&amp;quot;        &amp;quot;Selangor&amp;quot;       
## [137] &amp;quot;Selangor&amp;quot;        &amp;quot;Trengganu&amp;quot;       &amp;quot;Trengganu&amp;quot;       &amp;quot;Trengganu&amp;quot;      
## [141] &amp;quot;Trengganu&amp;quot;       &amp;quot;Trengganu&amp;quot;       &amp;quot;Trengganu&amp;quot;       &amp;quot;Trengganu&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, this is the plot for Terengganu.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;Trg &amp;lt;- Malaysia[138:144,]
plot(Trg)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-12-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;We going to the map this in ggplot, and stacked the map layer with the coordinate layer.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_spatvector(data = Trg, color = &amp;quot;grey&amp;quot;, fill = NA) +
  geom_point(data = clinic_trg, aes(x = longitude, y = latitude, color = &amp;quot;red&amp;quot;)) +
  theme_minimal() +
  theme(legend.position = &amp;quot;none&amp;quot;) +
  xlab(&amp;quot;Longitude&amp;quot;) +
  ylab(&amp;quot;Latitude&amp;quot;) +
  labs(title = &amp;quot;Desa clinic in Terengganu, Malaysia&amp;quot;, 
       subtitle = &amp;quot;(Data last updated: Klinik Desa - 9 Mac 2021)&amp;quot;,
       caption = expression(paste(italic(&amp;quot;Sumber data: https://www.data.gov.my/data/ms_MY/group/pemetaan&amp;quot;)))) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-13-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;geom_spatvector&lt;/code&gt; is from &lt;code&gt;tidyterra&lt;/code&gt; package. Alternatively, we can plot using &lt;code&gt;geom_sf&lt;/code&gt;but we need to convert the &lt;code&gt;SpatVector&lt;/code&gt; data into &lt;code&gt;sf&lt;/code&gt; object using &lt;code&gt;sf::st_as_sf&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot(data = sf::st_as_sf(Trg)) +
  geom_sf(color = &amp;quot;grey&amp;quot;, fill = NA) +
  geom_point(data = clinic_trg, aes(x = longitude, y = latitude, color = &amp;quot;red&amp;quot;)) +
  theme_minimal() +
  theme(legend.position = &amp;quot;none&amp;quot;) +
  xlab(&amp;quot;Longitude&amp;quot;) +
  ylab(&amp;quot;Latitude&amp;quot;) +
  labs(title = &amp;quot;Desa clinic in Terengganu, Malaysia&amp;quot;, 
       subtitle = &amp;quot;(Data last updated: Klinik Desa - 9 Mac 2021)&amp;quot;,
       caption = expression(paste(italic(&amp;quot;Sumber data: https://www.data.gov.my/data/ms_MY/group/pemetaan&amp;quot;)))) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-14-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Both approaches produce the same plot.&lt;/p&gt;
&lt;p&gt;We can further add district labels to the plots. For example, using the &lt;code&gt;geom_sf&lt;/code&gt;, we can stack it with &lt;code&gt;geom_sf_label&lt;/code&gt; layer. We can alternatively use &lt;code&gt;theme_void&lt;/code&gt; to remove the background and the map axis.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot(data = sf::st_as_sf(Trg)) +
  geom_sf(color = &amp;quot;grey&amp;quot;, fill = NA) +
  geom_sf_label(aes(label = NAME_2)) +
  geom_point(data = clinic_trg, aes(x = longitude, y = latitude, color = &amp;quot;red&amp;quot;)) +
  theme_void() +
  theme(legend.position = &amp;quot;none&amp;quot;) +
  xlab(&amp;quot;Longitude&amp;quot;) +
  ylab(&amp;quot;Latitude&amp;quot;) +
  labs(title = &amp;quot;Desa clinic in Terengganu, Malaysia&amp;quot;, 
       subtitle = &amp;quot;(Data last updated: Klinik Desa - 9 Mac 2021)&amp;quot;,
       caption = expression(paste(italic(&amp;quot;Sumber data: https://www.data.gov.my/data/ms_MY/group/pemetaan&amp;quot;)))) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/mapping-the-states-in-malaysia/index.en_files/figure-html/unnamed-chunk-15-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Making maps with R (my first attempt ever!)</title>
      <link>https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/</link>
      <pubDate>Fri, 12 Nov 2021 00:00:00 +0000</pubDate>
      <guid>https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/</guid>
      <description>
&lt;script src=&#34;https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/index.en_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;As written in the title of the post, this is my first try ever in making a map with R. I found a great data on the distribution of the clinics in Malaysia. The two types of clinic that we have here:&lt;/p&gt;
&lt;ol style=&#34;list-style-type: decimal&#34;&gt;
&lt;li&gt;Klinik 1Malaysia (1Malaysia clinic)&lt;/li&gt;
&lt;li&gt;Klinik Desa (Desa clinic)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Originally, these two data are a separated data. Both of the data can be downloaded from &lt;a href=&#34;https://www.data.gov.my/data/ms_MY/group/pemetaan&#34;&gt;here&lt;/a&gt;. Also, I have uploaded the data into my &lt;a href=&#34;https://github.com/tengku-hanis/clinic-data&#34;&gt;GitHub repo&lt;/a&gt; for those interested. Klinik Desa data have a latitude and longitude information, but Klinik 1Malaysia data does not.&lt;/p&gt;
&lt;p&gt;These are the required packages.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(rworldmap) #to get a Malaysia map
library(tidyverse)
library(tidygeocoder) #to get latitude and logitude&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Read the data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;clinic1m &amp;lt;- read.csv(&amp;quot;https://raw.githubusercontent.com/tengku-hanis/clinic-data/main/clinic1m.csv&amp;quot;)
clinicDesa &amp;lt;- read.csv(&amp;quot;https://raw.githubusercontent.com/tengku-hanis/clinic-data/main/clinicdesa.csv&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First, we need to get a latitude and longitude information for Klinik 1Malaysia data. So, we going to retrieve the coordinates based on the postal code, though this is not very accurate. We can use &lt;code&gt;tidygeocoder&lt;/code&gt; for this.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;clinic1m2 &amp;lt;- 
  clinic1m %&amp;gt;%
  mutate(country = &amp;quot;malaysia&amp;quot;) %&amp;gt;% 
  select(name, postcode, country) %&amp;gt;% 
  mutate(postcode = ifelse(nchar(postcode) == 4, paste0(0, postcode), postcode)) %&amp;gt;%
  geocode(postalcode = postcode, country = country, method = &amp;quot;osm&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Further checking on the data, we notice that 5 clinics have no coordinate info.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;clinic1m2 %&amp;gt;% filter(is.na(lat) | is.na(long))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## # A tibble: 5 x 5
##   name                                     postcode country    lat  long
##   &amp;lt;chr&amp;gt;                                    &amp;lt;chr&amp;gt;    &amp;lt;chr&amp;gt;    &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1 Klinik 1 Malaysia Bandar Lela            90700    malaysia    NA    NA
## 2 Klinik 1 Malaysia Batu Melintang         17250    malaysia    NA    NA
## 3 Klinik 1 Malaysia Cakerapurnama          45010    malaysia    NA    NA
## 4 Klinik 1 Malaysia Jelawat                16070    malaysia    NA    NA
## 5 Klinik 1 Malaysia Taman Kempadang Makmur 26060    malaysia    NA    NA&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;some-data-pre-processing&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Some data pre-processing&lt;/h2&gt;
&lt;p&gt;So, I found this &lt;a href=&#34;https://www.listendata.com/2020/11/zip-code-to-latitude-and-longitude.html&#34;&gt;data&lt;/a&gt; after some googling time, which give coordinate based on the postal code. So, we going to add in the missing coordinate based on this online data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;add_coord &amp;lt;- 
  read.table(header = T, text = &amp;quot;
postal_code    latitude   longitude
16070            6.0334    102.3499
26060            3.6228    102.3926
90700            5.8456    118.0571
26060            3.6228    102.3926&amp;quot;)

clinic1m2 &amp;lt;- 
  clinic1m2 %&amp;gt;% 
  mutate(lat = ifelse(postcode %in% add_coord$postal_code, add_coord$latitude, lat), 
         long = ifelse(postcode %in% add_coord$postal_code, add_coord$longitude, long)) %&amp;gt;% 
  drop_na() #drop 2 clinic1m&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Even after add in the missing coordinate, we still missing 2 coordinates. So, we going to drop those 2 clinics. Next, we combine both data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;all_clinic &amp;lt;- 
  clinic1m2 %&amp;gt;% 
  mutate(Type = &amp;quot;1Malaysia&amp;quot;) %&amp;gt;% 
  select(Type, lat, long) %&amp;gt;% 
  bind_rows(clinicDesa %&amp;gt;% 
              mutate(Type = &amp;quot;Desa&amp;quot;, 
                     lat = latitude, 
                     long = longitude) %&amp;gt;% 
              select(Type, lat, long))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s try plotting the data first.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot(all_clinic, aes(long, lat, color = Type)) +
  geom_point() +
  theme_minimal() #should remove the isolated two data&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/index.en_files/figure-html/unnamed-chunk-7-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;We have 2 isolated points from Klinik Desa data. We will drop these 2 points as well.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;all_clinic2 &amp;lt;- all_clinic %&amp;gt;% filter(long &amp;gt; 25)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;plotting-the-map&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Plotting the map&lt;/h2&gt;
&lt;p&gt;There are 2 ways to plot our data to Malaysia map, that we going to cover in this post.&lt;/p&gt;
&lt;div id=&#34;map-from-ggplot2&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;1) map from &lt;code&gt;ggplot2&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;First, we need to get the map.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;global &amp;lt;- map_data(&amp;quot;world&amp;quot;) #get map&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once, we retrieved the map, we need to filter the region to Malaysia. The rest of the codes are &lt;code&gt;ggplot2&lt;/code&gt; function as we know it.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() + 
  geom_polygon(data = global %&amp;gt;% filter(region == &amp;quot;Malaysia&amp;quot;), aes(x=long, y = lat, group = group), 
               fill = &amp;quot;gray85&amp;quot;) + 
  coord_fixed(1.3) +
  geom_point(data = all_clinic2, aes(x = long, y = lat, group = Type, color = Type, shape = Type)) +
  theme_void() + 
  xlab(&amp;quot;Longitude&amp;quot;) +
  ylab(&amp;quot;Latitude&amp;quot;) +
  labs(title = &amp;quot;Klinik 1Malaysia dan Klinik Desa di Malaysia&amp;quot;, 
       subtitle = &amp;quot;(Data dikemaskini: Klinik 1Malaysia - 16 Mac 2021, Klinik Desa - 9 Mac 2021)&amp;quot;,
       caption = expression(paste(italic(&amp;quot;Sumber data: https://www.data.gov.my/data/ms_MY/group/pemetaan&amp;quot;))), 
       color = &amp;quot;Jenis klinik:&amp;quot;, 
       shape = &amp;quot;Jenis klinik:&amp;quot;) +
  theme(plot.title = element_text(hjust = 0.5), 
        plot.subtitle = element_text(hjust = 0.5), 
        legend.position = &amp;quot;bottom&amp;quot;) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/index.en_files/figure-html/unnamed-chunk-10-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;map-from-rworldmap&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;2) map from &lt;code&gt;rworldmap&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The flow is similar, we need to get the map first. Then, restrict the map to Malaysia region.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;world &amp;lt;- getMap(resolution = &amp;quot;low&amp;quot;) #get map
msia &amp;lt;- world[world@data$ADMIN == &amp;quot;Malaysia&amp;quot;, ]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The rest of the codes are similar to the first approach. But, we going to change the theme a bit.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_polygon(data = msia, aes(x = long, y = lat, group = group), fill = NA, colour = &amp;quot;black&amp;quot;) +
  geom_point(data = all_clinic2, aes(x = long, y = lat, group = Type, color = Type, shape = Type)) +
  coord_quickmap() + 
  theme_minimal() + 
  xlab(&amp;quot;Longitude&amp;quot;) +
  ylab(&amp;quot;Latitude&amp;quot;) +
  labs(title = &amp;quot;Klinik 1Malaysia dan Klinik Desa di Malaysia&amp;quot;, 
       subtitle = &amp;quot;(Data dikemaskini: Klinik 1Malaysia - 16 Mac 2021, Klinik Desa - 9 Mac 2021)&amp;quot;,
       caption = expression(paste(italic(&amp;quot;Sumber data: https://www.data.gov.my/data/ms_MY/group/pemetaan&amp;quot;))), 
       color = &amp;quot;Jenis klinik:&amp;quot;, 
       shape = &amp;quot;Jenis klinik:&amp;quot;) +
  theme(plot.title = element_text(hjust = 0.5), 
        plot.subtitle = element_text(hjust = 0.5), 
        legend.position = &amp;quot;bottom&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/making-maps-with-r-my-first-attempt-ever/index.en_files/figure-html/unnamed-chunk-12-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;conclusion&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The coordinates that we have are not as accurate as it should, or maybe there is something wrong that I miss along the way. As we can see, we have clinics on the ocean. As far as I know, we Malaysian are not that advanced yet. Also, noticed that we severely lacking clinics in Sarawak, given that our data is correct.&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Some COVID-19 plots for Southeast Asian countries</title>
      <link>https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/</link>
      <pubDate>Wed, 10 Nov 2021 00:00:00 +0000</pubDate>
      <guid>https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/</guid>
      <description>
&lt;script src=&#34;https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/index.en_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;Recently, I found a GitHub &lt;a href=&#34;https://github.com/owid/covid-19-data/tree/master/public/data&#34;&gt;repo&lt;/a&gt; containing a global COVID-19 dataset. I thought, why not try to do some plotting for Southeast Asian countries. So, I downloaded the data and limited the data to Southeast Asian countries only (Brunei, Indonesia, Malaysia, Philippines, Singapore, Thailand and Vietnam). I have uploaded this restricted data to my GitHub &lt;a href=&#34;https://github.com/tengku-hanis/data-owid-covid&#34;&gt;repo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We are not going to do anything fancy, just some visualisations.&lt;/p&gt;
&lt;p&gt;Let’s begin by reading the data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidyverse)
covid_sea &amp;lt;- read_csv(&amp;quot;https://raw.githubusercontent.com/tengku-hanis/data-owid-covid/main/covid_sea.csv&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We are going to compare between each Southeast Asian countries in terms of:&lt;/p&gt;
&lt;ol style=&#34;list-style-type: decimal&#34;&gt;
&lt;li&gt;Daily cases&lt;/li&gt;
&lt;li&gt;Daily deaths&lt;/li&gt;
&lt;li&gt;Daily tests&lt;/li&gt;
&lt;li&gt;Daily vaccinations&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Before that, we need to make a function, as all the above items have a generic things to plot with the exception on y axis.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;easy_plot &amp;lt;- function(var1, lab_title, yaxis_lab, span = 0.14){
  covid_sea %&amp;gt;% 
    select(date, location, {{var1}}) %&amp;gt;% 
    drop_na() %&amp;gt;% 
    ggplot(aes(date, {{var1}}, color = location)) +
    geom_smooth(se = F, span = 0.14) +
    geom_point(aes(color = location), alpha = 0.2) +
    geom_line(aes(color = location), alpha = 0.2, linetype = &amp;quot;dashed&amp;quot;) +
    labs(title = {{lab_title}}) +
    ylab({{yaxis_lab}}) +
    xlab(&amp;quot;Date&amp;quot;) +
    theme_minimal() 
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;var1 is going to be the item/variable that we want to compare, lab_title is the plot title, yaxis_lab is the label on the y axis, and span is just how smooth our smoothen line should be.&lt;/p&gt;
&lt;div id=&#34;daily-cases&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Daily cases&lt;/h2&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;easy_plot(new_cases, &amp;quot;Daily cases for southeast Asian countries&amp;quot;, &amp;quot;Daily cases&amp;quot;, span = 0.8)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/index.en_files/figure-html/unnamed-chunk-3-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;We cannot compare in terms of the frequency as big countries like Indonesia is expected to had a higher number of daily cases. A smoothen line though very basic, may indicate a simple trend. Thailand, Malaysia, Philippines and Indonesia seems to had a decreasing trend of cases. On the other hand, the daily cases in Vietnam seems to start to increase. Singapore had a more stabilised trend of cases, though a higher number of cases was observed in the latest period. Lastly, Brunei had too little cases, for us to see any sort of trend at the scale of the between countries comparison.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;daily-deaths&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Daily deaths&lt;/h2&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;easy_plot(new_deaths, &amp;quot;Daily deaths for southeast Asian countries&amp;quot;, &amp;quot;Daily deaths&amp;quot;, span = 0.8)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/index.en_files/figure-html/unnamed-chunk-4-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Philippines and Indonesia seems started to had a bit of increasing trend. Other countries look okay.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;daily-tests&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Daily tests&lt;/h2&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;easy_plot(new_tests, &amp;quot;Daily tests for southeast Asian countries&amp;quot;, &amp;quot;Daily tests&amp;quot;, span = 0.2)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/index.en_files/figure-html/unnamed-chunk-5-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The daily tests plot looks a bit weird for Vietnam. Actually, the daily tests below zero are not avaliable (not sure if there is no test done in the period or the values is just missing). Hence, the weird looking plot for Vietnam. Data for Brunei and Thailand are not available. Malaysia seems to be quite aggressive in COVID-19 testing, even on par with Indonesia. Also, Vietnam seems to be very aggressive in the latest period, probably to cover the lack of COVID-19 testing previously.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;daily-vaccinations&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Daily vaccinations&lt;/h2&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;easy_plot(new_vaccinations, &amp;quot;Daily vaccinations for southeast Asian countries&amp;quot;, &amp;quot;Daily vaccinations&amp;quot;, span = 0.9)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/index.en_files/figure-html/unnamed-chunk-6-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Malaysia and Singapore had quite a similar distribution. Vietnam, Philippines, Thailand and Indonesia quite similar in which they had a series of wave in the rate of vaccinations, though the trend of wave for Thailand is less obvious. Again, the number in Brunei was too little for us to see any trend or distribution at this scale.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;malaysia-situation&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Malaysia situation&lt;/h2&gt;
&lt;p&gt;Let’s do a plot, specific to Malaysia. We going to scale the numbers, so that we able to see a comparison in term of trend or distribution.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;covid_sea %&amp;gt;% 
  filter(location == &amp;quot;Malaysia&amp;quot;) %&amp;gt;% 
  mutate(new_cases = scale(new_cases), 
         new_deaths = scale(new_deaths), 
         new_tests = scale(new_tests), 
         new_vaccinations = scale(new_vaccinations)) %&amp;gt;% 
  ggplot(aes(date)) +
  geom_line(aes(y = new_cases, color = &amp;quot;new_cases&amp;quot;), alpha = 0.3) +
  geom_line(aes(y = new_deaths, color = &amp;quot;new_deaths&amp;quot;), alpha = 0.3) +
  geom_line(aes(y = new_tests, color = &amp;quot;new_tests&amp;quot;), alpha = 0.3) +
  geom_line(aes(y = new_vaccinations, color = &amp;quot;new_vaccinations&amp;quot;), alpha = 0.3) +
  geom_point(aes(y = new_cases, color = &amp;quot;new_cases&amp;quot;), alpha = 0.3) +
  geom_point(aes(y = new_deaths, color = &amp;quot;new_deaths&amp;quot;), alpha = 0.3) +
  geom_point(aes(y = new_tests, color = &amp;quot;new_tests&amp;quot;), alpha = 0.3) +
  geom_point(aes(y = new_vaccinations, color = &amp;quot;new_vaccinations&amp;quot;), alpha = 0.3) +
  geom_smooth(aes(y = new_cases, color = &amp;quot;new_cases&amp;quot;), se = F, span = 0.3) +
  geom_smooth(aes(y = new_deaths, color = &amp;quot;new_deaths&amp;quot;), se = F, span = 0.3) +
  geom_smooth(aes(y = new_tests, color = &amp;quot;new_tests&amp;quot;), se = F, span = 0.3) +
  geom_smooth(aes(y = new_vaccinations, color = &amp;quot;new_vaccinations&amp;quot;), se = F, span = 0.6) +
  labs(title = &amp;quot;Situation in Malaysia&amp;quot;) +
  ylab(&amp;quot;Scaled Frequency&amp;quot;) +
  xlab(&amp;quot;Date&amp;quot;) +
  guides(color = guide_legend(&amp;quot;Items&amp;quot;)) +
  scale_color_discrete(labels = c(&amp;quot;Daily cases&amp;quot;, &amp;quot;Daily deaths&amp;quot;, &amp;quot;Daily tests&amp;quot;, &amp;quot;Daily vaccinations&amp;quot;)) +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://tengkuhanis.netlify.app/post/some-covid-19-plots-for-southeast-asian-countries/index.en_files/figure-html/unnamed-chunk-7-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Interestingly, as the number of vaccination increased up to a certain threshold, the number of daily cases and daily deaths started to decreased. Obviously, the daily testing also decreased as in Malaysia, COVID-19 testing is done based on suspected cases and their persons of contact instead of mass testing.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer: Please take anything written here with a massive grain of salt.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Data source:
&lt;a href=&#34;https://github.com/owid/covid-19-data/tree/master/public/data&#34; class=&#34;uri&#34;&gt;https://github.com/owid/covid-19-data/tree/master/public/data&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>How many Malaysian should be vaccinated to get herd immunity from COVID-19?</title>
      <link>https://tengkuhanis.netlify.app/post/how-many-malaysian-should-be-vaccinated-to-get-herd-immunity-from-covid-19/</link>
      <pubDate>Mon, 07 Dec 2020 00:00:00 +0000</pubDate>
      <guid>https://tengkuhanis.netlify.app/post/how-many-malaysian-should-be-vaccinated-to-get-herd-immunity-from-covid-19/</guid>
      <description>
&lt;script src=&#34;https://tengkuhanis.netlify.app/post/how-many-malaysian-should-be-vaccinated-to-get-herd-immunity-from-covid-19/index.en_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;Recently I have read an &lt;a href=&#34;https://codeblue.galencentre.org/2020/11/27/malaysia-buying-pfizers-ultra-cold-covid-19-vaccine-posing-major-distribution-issues/#:~:text=According%20to%20BioSpace%2C%20the%20Covid,price%20sold%20to%20the%20US&#34;&gt;article&lt;/a&gt; that the Malaysian government have made a deal with Pfizer for 6.4 million Malaysian to be vaccinated. So, I am wondering what is the minimal number of people should be vaccinated.&lt;/p&gt;
&lt;p&gt;I have also come across this interesting &lt;a href=&#34;https://www.cebm.net/covid-19/when-will-it-be-over-an-introduction-to-viral-reproduction-numbers-r0-and-re/&#34;&gt;article&lt;/a&gt;, which explains how we can calculate a minimal number of people to be vaccinated to achieves herd immunity based on R naught (R&lt;sub&gt;0&lt;/sub&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;R naught (R&lt;sub&gt;0&lt;/sub&gt;)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The basic idea of R&lt;sub&gt;0&lt;/sub&gt; or basic reproduction number is quite simple. It describes how many secondary infections will derive from the first case. I think Figure 1 below describes this idea very well.&lt;/p&gt;
&lt;div class=&#34;figure&#34; style=&#34;text-align: center&#34;&gt;&lt;span style=&#34;display:block;&#34; id=&#34;fig:unnamed-chunk-1&#34;&gt;&lt;/span&gt;
&lt;img src=&#34;r0.png&#34; alt=&#34;Basic idea of R~0~(image from https://www.atrainceu.com/content/3-basic-reproduction-number-r-naught)&#34; width=&#34;60%&#34; /&gt;
&lt;p class=&#34;caption&#34;&gt;
Figure 1: Basic idea of R&lt;sub&gt;0&lt;/sub&gt;(image from &lt;a href=&#34;https://www.atrainceu.com/content/3-basic-reproduction-number-r-naught&#34; class=&#34;uri&#34;&gt;https://www.atrainceu.com/content/3-basic-reproduction-number-r-naught&lt;/a&gt;)
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;So, R&lt;sub&gt;0&lt;/sub&gt; can be affected by a few factors, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;proportion of susceptible people at the initial outbreak&lt;/li&gt;
&lt;li&gt;infectiousness of the virus or the disease&lt;/li&gt;
&lt;li&gt;rate of recovery or death&lt;/li&gt;
&lt;li&gt;and a few other factors&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As R&lt;sub&gt;0&lt;/sub&gt; increases more than 1, the spread of the disease will increases, while R&lt;sub&gt;0&lt;/sub&gt; below 1 indicates the spread of the disease will decrease and eventually dies out.&lt;/p&gt;
&lt;p&gt;However, I noticed that quite a few including KKM (Ministry of Health, Malaysia) have used the term R&lt;sub&gt;0&lt;/sub&gt; in their reports instead of R&lt;sub&gt;e&lt;/sub&gt; or R&lt;sub&gt;t&lt;/sub&gt; which is the effective reproduction number or time-varying reproduction number. R&lt;sub&gt;0&lt;/sub&gt; refers to the initial reproduction number at the beginning of the outbreak. The “naught” or “zero” in R naught (R&lt;sub&gt;0&lt;/sub&gt;) is referring to population condition that has zero immunity to the disease.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Herd immunity&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Herd immunity is said to occur when a significant proportion of the population is immunized. Subsequently, those whose susceptible (not immunized) will be protected.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How many should be vaccinated&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So, back to the initial topic. We can use the formula below to answer this question.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math display&#34;&gt;\[P_i &amp;gt; 1 - \frac{1}{R_0}\]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;P&lt;sub&gt;i&lt;/sub&gt; refers to the number of proportion that should be immunized or in this case, vaccinated.&lt;/p&gt;
&lt;p&gt;So, after googling, I found one calculation by my lecturer in Biostat Unit, USM, &lt;a href=&#34;https://wnarifin.github.io/&#34;&gt;Dr Wan Arifin&lt;/a&gt; and his colleague. The R&lt;sub&gt;0&lt;/sub&gt; based on his &lt;a href=&#34;https://wnarifin.github.io/covid-19-malaysia-sir/&#34;&gt;calculation&lt;/a&gt; is 2.673. Also, I found another &lt;a href=&#34;https://codeblue.galencentre.org/2020/04/10/mco-slashed-malaysia-covid-19-infection-rate-by-over-three-times/&#34;&gt;article&lt;/a&gt; reported that the R&lt;sub&gt;0&lt;/sub&gt; is 3.55 in March, according to KKM.&lt;/p&gt;
&lt;p&gt;Malaysian’s population is estimated at &lt;a href=&#34;https://www.dosm.gov.my/v1/index.php?r=column/cthemeByCat&amp;amp;cat=155&amp;amp;bul_id=OVByWjg5YkQ3MWFZRTN5bDJiaEVhZz09&amp;amp;menu_id=L0pheU43NWJwRWVSZklWdzQ4TlhUUT09&#34;&gt;32.7 million&lt;/a&gt; by the Department of Statistics, Malaysia (DOSM). So, using the formula above, about 63% to 72% of Malaysian population should vaccinated, and this translates to about 20.6 to 23.5 million people.&lt;/p&gt;
&lt;p&gt;The deal that the Malaysian government made with Pfizer is far from enough, but of course, this is a very good and quick decision. We also have other vaccines like Moderna’s vaccine coming up.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer: This is just my opinion. Please take it with a massive grain of salt.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
