<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts | Data Science in Agriculture</title><link>https://luanppott.netlify.app/post/</link><atom:link href="https://luanppott.netlify.app/post/index.xml" rel="self" type="application/rss+xml"/><description>Posts</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><image><url>https://luanppott.netlify.app/media/icon_hu64dbc3ef6cc8eee8a271968fd359f750_313029_512x512_fill_lanczos_center_2.png</url><title>Posts</title><link>https://luanppott.netlify.app/post/</link></image><item><title>R - Data wrangling utilizing the most common functions from tidyverse package collection</title><link>https://luanppott.netlify.app/post/post2/</link><pubDate>Thu, 14 Oct 2021 00:00:00 +0000</pubDate><guid>https://luanppott.netlify.app/post/post2/</guid><description>
&lt;script src="https://luanppott.netlify.app/post/post2/index.en_files/header-attrs/header-attrs.js">&lt;/script>
&lt;div id="data-wrangling-utilizing-the-most-common-functions-from-tidyverse-package-collection." class="section level1">
&lt;h1>Data wrangling utilizing the most common functions from tidyverse package collection.&lt;/h1>
&lt;/div>
&lt;div id="loading-the-package" class="section level1">
&lt;h1>Loading the package&lt;/h1>
&lt;pre class="r">&lt;code>library(tidyverse)&lt;/code>&lt;/pre>
&lt;p>URL link of data from data collection and remote sensing on GitHub &lt;a href="https://github.com/luanpott10/Class" class="uri">https://github.com/luanpott10/Class&lt;/a>
You will need the raw file &lt;a href="https://raw.githubusercontent.com/luanpott10/Class/main/data_crops.csv" class="uri">https://raw.githubusercontent.com/luanpott10/Class/main/data_crops.csv&lt;/a>&lt;/p>
&lt;/div>
&lt;div id="loading-the-data" class="section level1">
&lt;h1>Loading the data&lt;/h1>
&lt;pre class="r">&lt;code>data &amp;lt;- read.csv(&amp;quot;https://raw.githubusercontent.com/luanpott10/Class/main/data_crops.csv&amp;quot;)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="a-rapid-view-of-the-data" class="section level1">
&lt;h1>A rapid view of the data&lt;/h1>
&lt;div id="functions-that-can-be-used" class="section level2">
&lt;h2>Functions that can be used&lt;/h2>
&lt;div id="glimpse" class="section level5">
&lt;h5>&lt;code>glimpse()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="head" class="section level5">
&lt;h5>&lt;code>head()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="tail" class="section level5">
&lt;h5>&lt;code>tail()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="summary" class="section level5">
&lt;h5>&lt;code>summary()&lt;/code>&lt;/h5>
&lt;pre class="r">&lt;code>data |&amp;gt; glimpse()
## Rows: 100
## Columns: 9
## $ ï..n &amp;lt;int&amp;gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1~
## $ latitude &amp;lt;dbl&amp;gt; -28.59329, -30.87459, -28.84481, -30.65571, -28.85978, -28.4~
## $ longitude &amp;lt;dbl&amp;gt; -52.64978, -51.72551, -53.46126, -55.11848, -53.61491, -55.0~
## $ class &amp;lt;chr&amp;gt; &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soyb~
## $ b0_GCVI &amp;lt;dbl&amp;gt; -1.48824394, -1.07909429, 0.16900872, -0.92421901, -0.671991~
## $ b1_GCVI &amp;lt;dbl&amp;gt; -3.8113625, -1.8287302, -2.0509982, -2.5976772, -2.8033531, ~
## $ b2_GCVI &amp;lt;dbl&amp;gt; -6.3380713, -4.8378959, -2.7416265, -4.2464180, -4.3012776, ~
## $ b3_GCVI &amp;lt;dbl&amp;gt; 1.2918025, 2.0158091, -1.1819744, 0.8886908, -0.2094595, 2.6~
## $ b4_GCVI &amp;lt;dbl&amp;gt; -4.631691, -2.661626, -2.707749, -3.352147, -3.434427, -7.33~
data |&amp;gt; head(5)
## ï..n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 1 -28.59329 -52.64978 soybean -1.4882439 -3.811363 -6.338071 1.2918025
## 2 2 -30.87459 -51.72551 soybean -1.0790943 -1.828730 -4.837896 2.0158091
## 3 3 -28.84481 -53.46126 soybean 0.1690087 -2.050998 -2.741627 -1.1819744
## 4 4 -30.65571 -55.11848 soybean -0.9242190 -2.597677 -4.246418 0.8886908
## 5 5 -28.85978 -53.61491 soybean -0.6719911 -2.803353 -4.301278 -0.2094595
## b4_GCVI
## 1 -4.631691
## 2 -2.661626
## 3 -2.707749
## 4 -3.352147
## 5 -3.434427
data |&amp;gt; tail(5)
## ï..n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 96 96 -28.53374 -52.84692 corn 5.628807 1.4232943 5.189684 -3.280593
## 97 97 -27.67757 -54.75618 corn 7.803896 5.7830925 7.469813 -1.889733
## 98 98 -28.32241 -51.33973 corn 3.854038 -0.4112832 2.829001 -2.718110
## 99 99 -28.13302 -51.36585 corn 2.423372 -1.6455027 1.057501 -2.884991
## 100 100 -28.05637 -54.54361 corn 7.691086 4.8666124 7.726856 -2.407301
## b4_GCVI
## 96 2.666456
## 97 5.124163
## 98 0.711688
## 99 -1.349620
## 100 4.228607
data |&amp;gt; summary()
## ï..n latitude longitude class
## Min. : 1.00 Min. :-33.67 Min. :-55.86 Length:100
## 1st Qu.: 25.75 1st Qu.:-28.90 1st Qu.:-53.62 Class :character
## Median : 50.50 Median :-28.47 Median :-52.83 Mode :character
## Mean : 50.50 Mean :-28.83 Mean :-53.03
## 3rd Qu.: 75.25 3rd Qu.:-27.96 3rd Qu.:-52.18
## Max. :100.00 Max. :-27.22 Max. :-50.48
## b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## Min. :-10.400 Min. :-7.3446 Min. :-19.354 Min. :-6.16632
## 1st Qu.: -1.373 1st Qu.:-3.0439 1st Qu.: -5.601 1st Qu.:-1.93480
## Median : 0.650 Median :-1.7779 Median : -2.768 Median :-0.07191
## Mean : 1.181 Mean :-0.9485 Mean : -1.731 Mean :-0.04668
## 3rd Qu.: 4.529 3rd Qu.: 1.1793 3rd Qu.: 3.622 3rd Qu.: 1.53019
## Max. : 13.737 Max. : 6.5656 Max. : 17.014 Max. : 6.54275
## b4_GCVI
## Min. :-7.332
## 1st Qu.:-4.117
## Median :-2.728
## Mean :-1.386
## 3rd Qu.: 2.069
## Max. : 5.124&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;/div>
&lt;div id="select" class="section level1">
&lt;h1>Select&lt;/h1>
&lt;div id="select-function-is-used-for-selecting-columns-in-a-data-frame." class="section level2">
&lt;h2>&lt;code>select&lt;/code> function is used for selecting columns in a data frame.&lt;/h2>
&lt;/div>
&lt;div id="here-i-brought-you-some-examples-of-the-select-function-for-selecting-different-columns-in-different-ways." class="section level2">
&lt;h2>Here I brought you some examples of the &lt;code>select&lt;/code> function for selecting different columns in different ways.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; select(1) |&amp;gt; head(6)
## ï..n
## 1 1
## 2 2
## 3 3
## 4 4
## 5 5
## 6 6
data |&amp;gt; select(last_col()) |&amp;gt; head(6)
## b4_GCVI
## 1 -4.631691
## 2 -2.661626
## 3 -2.707749
## 4 -3.352147
## 5 -3.434427
## 6 -7.331731
data |&amp;gt; select(c(class,b0_GCVI,b1_GCVI,b2_GCVI,b3_GCVI,b4_GCVI)) |&amp;gt; head(6)
## class b0_GCVI b1_GCVI b2_GCVI b3_GCVI b4_GCVI
## 1 soybean -1.4882439 -3.811363 -6.338071 1.2918025 -4.631691
## 2 soybean -1.0790943 -1.828730 -4.837896 2.0158091 -2.661626
## 3 soybean 0.1690087 -2.050998 -2.741627 -1.1819744 -2.707749
## 4 soybean -0.9242190 -2.597677 -4.246418 0.8886908 -3.352147
## 5 soybean -0.6719911 -2.803353 -4.301278 -0.2094595 -3.434427
## 6 soybean -5.1542411 -7.344623 -10.879841 2.6003060 -7.331731
data |&amp;gt; select(-c(ï..n,latitude,longitude)) |&amp;gt; head(6)
## class b0_GCVI b1_GCVI b2_GCVI b3_GCVI b4_GCVI
## 1 soybean -1.4882439 -3.811363 -6.338071 1.2918025 -4.631691
## 2 soybean -1.0790943 -1.828730 -4.837896 2.0158091 -2.661626
## 3 soybean 0.1690087 -2.050998 -2.741627 -1.1819744 -2.707749
## 4 soybean -0.9242190 -2.597677 -4.246418 0.8886908 -3.352147
## 5 soybean -0.6719911 -2.803353 -4.301278 -0.2094595 -3.434427
## 6 soybean -5.1542411 -7.344623 -10.879841 2.6003060 -7.331731
data |&amp;gt; select(starts_with(&amp;quot;b&amp;quot;)) |&amp;gt; head(6)
## b0_GCVI b1_GCVI b2_GCVI b3_GCVI b4_GCVI
## 1 -1.4882439 -3.811363 -6.338071 1.2918025 -4.631691
## 2 -1.0790943 -1.828730 -4.837896 2.0158091 -2.661626
## 3 0.1690087 -2.050998 -2.741627 -1.1819744 -2.707749
## 4 -0.9242190 -2.597677 -4.246418 0.8886908 -3.352147
## 5 -0.6719911 -2.803353 -4.301278 -0.2094595 -3.434427
## 6 -5.1542411 -7.344623 -10.879841 2.6003060 -7.331731
data |&amp;gt; select(ends_with(&amp;quot;GCVI&amp;quot;)) |&amp;gt; head(6)
## b0_GCVI b1_GCVI b2_GCVI b3_GCVI b4_GCVI
## 1 -1.4882439 -3.811363 -6.338071 1.2918025 -4.631691
## 2 -1.0790943 -1.828730 -4.837896 2.0158091 -2.661626
## 3 0.1690087 -2.050998 -2.741627 -1.1819744 -2.707749
## 4 -0.9242190 -2.597677 -4.246418 0.8886908 -3.352147
## 5 -0.6719911 -2.803353 -4.301278 -0.2094595 -3.434427
## 6 -5.1542411 -7.344623 -10.879841 2.6003060 -7.331731
data |&amp;gt; select(where(is.numeric)) |&amp;gt; head(6)
## ï..n latitude longitude b0_GCVI b1_GCVI b2_GCVI b3_GCVI b4_GCVI
## 1 1 -28.59329 -52.64978 -1.4882439 -3.811363 -6.338071 1.2918025 -4.631691
## 2 2 -30.87459 -51.72551 -1.0790943 -1.828730 -4.837896 2.0158091 -2.661626
## 3 3 -28.84481 -53.46126 0.1690087 -2.050998 -2.741627 -1.1819744 -2.707749
## 4 4 -30.65571 -55.11848 -0.9242190 -2.597677 -4.246418 0.8886908 -3.352147
## 5 5 -28.85978 -53.61491 -0.6719911 -2.803353 -4.301278 -0.2094595 -3.434427
## 6 6 -28.41732 -55.03171 -5.1542411 -7.344623 -10.879841 2.6003060 -7.331731&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="arrange" class="section level1">
&lt;h1>Arrange&lt;/h1>
&lt;div id="arrange-function-is-used-for-orders-the-rows-of-a-data-frame-by-the-values-of-selected-columns." class="section level2">
&lt;h2>&lt;code>arrange&lt;/code> function is used for orders the rows of a data frame by the values of selected columns.&lt;/h2>
&lt;/div>
&lt;div id="in-some-cases-we-would-like-to-see-the-ordered-rows-according-a-determined-column-for-that-we-use-arrange-function." class="section level2">
&lt;h2>In some cases we would like to see the ordered rows according a determined column, for that we use &lt;code>arrange&lt;/code> function.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; arrange(b4_GCVI) |&amp;gt; head(6)
## ï..n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 6 -28.41732 -55.03171 soybean -5.154241 -7.344623 -10.879841 2.600306
## 2 44 -27.94593 -52.35423 soybean -6.849492 -6.901615 -13.810637 4.647782
## 3 11 -29.02970 -54.92061 soybean -10.400090 -6.194132 -19.353834 6.542745
## 4 31 -28.20905 -51.63171 soybean -3.497307 -5.756842 -9.003927 1.384130
## 5 18 -27.71189 -52.56109 soybean -4.217597 -5.241977 -10.647408 3.294080
## 6 14 -32.11317 -53.16475 soybean -4.723501 -4.550052 -11.359418 2.981974
## b4_GCVI
## 1 -7.331731
## 2 -7.022087
## 3 -6.669860
## 4 -6.664257
## 5 -5.579582
## 6 -5.544666&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="relocate" class="section level1">
&lt;h1>Relocate&lt;/h1>
&lt;div id="relocate-function-change-column-positions." class="section level2">
&lt;h2>&lt;code>relocate&lt;/code> function change column positions.&lt;/h2>
&lt;/div>
&lt;div id="generally-in-a-machine-learning-model-we-have-the-last-column-as-the-label-for-do-that-we-can-use-the-relocate-function." class="section level2">
&lt;h2>Generally in a machine learning model we have the last column as the label, for do that we can use the &lt;code>relocate&lt;/code> function.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; relocate(-class) |&amp;gt; head(6)
## ï..n latitude longitude b0_GCVI b1_GCVI b2_GCVI b3_GCVI b4_GCVI
## 1 1 -28.59329 -52.64978 -1.4882439 -3.811363 -6.338071 1.2918025 -4.631691
## 2 2 -30.87459 -51.72551 -1.0790943 -1.828730 -4.837896 2.0158091 -2.661626
## 3 3 -28.84481 -53.46126 0.1690087 -2.050998 -2.741627 -1.1819744 -2.707749
## 4 4 -30.65571 -55.11848 -0.9242190 -2.597677 -4.246418 0.8886908 -3.352147
## 5 5 -28.85978 -53.61491 -0.6719911 -2.803353 -4.301278 -0.2094595 -3.434427
## 6 6 -28.41732 -55.03171 -5.1542411 -7.344623 -10.879841 2.6003060 -7.331731
## class
## 1 soybean
## 2 soybean
## 3 soybean
## 4 soybean
## 5 soybean
## 6 soybean&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="filter" class="section level1">
&lt;h1>Filter&lt;/h1>
&lt;div id="filter-function-is-used-to-subset-a-data-frame-retaining-all-rows-that-satisfy-your-conditions." class="section level2">
&lt;h2>&lt;code>filter&lt;/code> function is used to subset a data frame, retaining all rows that satisfy your conditions.&lt;/h2>
&lt;/div>
&lt;div id="the-most-common-operators-that-are-useful-to-build-the-conditions-are" class="section level2">
&lt;h2>The most common operators that are useful to build the conditions are:&lt;/h2>
&lt;div id="section" class="section level5">
&lt;h5>&lt;code>==&lt;/code>, &lt;code>&amp;gt;&lt;/code>, &lt;code>&amp;gt;=&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="xor" class="section level5">
&lt;h5>&lt;code>&amp;amp;&lt;/code>, &lt;code>|&lt;/code>, &lt;code>!&lt;/code>, &lt;code>xor()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="is.na" class="section level5">
&lt;h5>&lt;code>is.na()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="between-near" class="section level5">
&lt;h5>&lt;code>between()&lt;/code>, &lt;code>near()&lt;/code>&lt;/h5>
&lt;/div>
&lt;/div>
&lt;div id="we-also-may-put-more-than-one-filter-in-the-same-filter-function." class="section level2">
&lt;h2>We also may put more than one filter in the same &lt;code>filter&lt;/code> function.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; filter(class == &amp;quot;soybean&amp;quot;, b4_GCVI &amp;gt; -4) |&amp;gt; head(6)
## ï..n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 2 -30.87459 -51.72551 soybean -1.0790943 -1.828730 -4.837896 2.0158091
## 2 3 -28.84481 -53.46126 soybean 0.1690087 -2.050998 -2.741627 -1.1819744
## 3 4 -30.65571 -55.11848 soybean -0.9242190 -2.597677 -4.246418 0.8886908
## 4 5 -28.85978 -53.61491 soybean -0.6719911 -2.803353 -4.301278 -0.2094595
## 5 9 -30.80493 -55.27339 soybean -0.9067734 -3.203305 -4.744385 0.5329000
## 6 13 -31.31976 -53.99590 soybean -2.4681277 -2.352393 -7.690125 3.9750807
## b4_GCVI
## 1 -2.661626
## 2 -2.707749
## 3 -3.352147
## 4 -3.434427
## 5 -3.771788
## 6 -1.823997&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="rename" class="section level1">
&lt;h1>Rename&lt;/h1>
&lt;div id="rename-changes-the-names-of-individual-variables." class="section level2">
&lt;h2>&lt;code>rename&lt;/code> changes the names of individual variables.&lt;/h2>
&lt;/div>
&lt;div id="column-names-in-datasets-should-be-short-inuitive-and-complete.-for-that-many-times-we-need-to-rename-columns-for-the-dataset." class="section level2">
&lt;h2>Column names in datasets should be short, inuitive and complete. For that many times we need to rename columns for the dataset.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; rename(n = ï..n) |&amp;gt; head(6)
## n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 1 -28.59329 -52.64978 soybean -1.4882439 -3.811363 -6.338071 1.2918025
## 2 2 -30.87459 -51.72551 soybean -1.0790943 -1.828730 -4.837896 2.0158091
## 3 3 -28.84481 -53.46126 soybean 0.1690087 -2.050998 -2.741627 -1.1819744
## 4 4 -30.65571 -55.11848 soybean -0.9242190 -2.597677 -4.246418 0.8886908
## 5 5 -28.85978 -53.61491 soybean -0.6719911 -2.803353 -4.301278 -0.2094595
## 6 6 -28.41732 -55.03171 soybean -5.1542411 -7.344623 -10.879841 2.6003060
## b4_GCVI
## 1 -4.631691
## 2 -2.661626
## 3 -2.707749
## 4 -3.352147
## 5 -3.434427
## 6 -7.331731&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="mutate" class="section level1">
&lt;h1>Mutate&lt;/h1>
&lt;div id="mutate-is-utilized-to-create-or-transform-variables." class="section level2">
&lt;h2>&lt;code>mutate&lt;/code> is utilized to create or transform variables.&lt;/h2>
&lt;/div>
&lt;div id="across-makes-it-easy-to-apply-the-same-transformation-to-multiple-columns." class="section level2">
&lt;h2>&lt;code>across&lt;/code> makes it easy to apply the same transformation to multiple columns.&lt;/h2>
&lt;/div>
&lt;div id="across-generally-it-is-used-into-summarise-and-mutate-functions." class="section level2">
&lt;h2>&lt;code>across&lt;/code> generally it is used into &lt;code>summarise()&lt;/code> and &lt;code>mutate()&lt;/code> functions.&lt;/h2>
&lt;/div>
&lt;div id="in-this-example-we-are-transforming---rounding-to-2-decimals-the-double-variables-except-latitude-and-longitude." class="section level2">
&lt;h2>In this example we are transforming - rounding to 2 decimals the double variables except latitude and longitude.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt;
mutate(across(where(is.double) &amp;amp; !c(latitude, longitude), ~ round(.x,2))) |&amp;gt; head(6)
## ï..n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI b4_GCVI
## 1 1 -28.59329 -52.64978 soybean -1.49 -3.81 -6.34 1.29 -4.63
## 2 2 -30.87459 -51.72551 soybean -1.08 -1.83 -4.84 2.02 -2.66
## 3 3 -28.84481 -53.46126 soybean 0.17 -2.05 -2.74 -1.18 -2.71
## 4 4 -30.65571 -55.11848 soybean -0.92 -2.60 -4.25 0.89 -3.35
## 5 5 -28.85978 -53.61491 soybean -0.67 -2.80 -4.30 -0.21 -3.43
## 6 6 -28.41732 -55.03171 soybean -5.15 -7.34 -10.88 2.60 -7.33&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="recode" class="section level1">
&lt;h1>Recode&lt;/h1>
&lt;div id="recode-is-utilized-to-recodes-a-numeric-vector-character-vector-or-factor-according-to-simple-recode-specifications." class="section level2">
&lt;h2>&lt;code>recode&lt;/code> is utilized to recodes a numeric vector, character vector, or factor according to simple recode specifications.&lt;/h2>
&lt;/div>
&lt;div id="for-more-complicated-criteria-use-case_when." class="section level2">
&lt;h2>For more complicated criteria, use &lt;code>case_when()&lt;/code>.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; mutate(specie=recode(class,
soybean=&amp;quot;Glycine max&amp;quot;,
corn=&amp;quot;Zea mays&amp;quot;)) |&amp;gt; head(6)
## ï..n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 1 -28.59329 -52.64978 soybean -1.4882439 -3.811363 -6.338071 1.2918025
## 2 2 -30.87459 -51.72551 soybean -1.0790943 -1.828730 -4.837896 2.0158091
## 3 3 -28.84481 -53.46126 soybean 0.1690087 -2.050998 -2.741627 -1.1819744
## 4 4 -30.65571 -55.11848 soybean -0.9242190 -2.597677 -4.246418 0.8886908
## 5 5 -28.85978 -53.61491 soybean -0.6719911 -2.803353 -4.301278 -0.2094595
## 6 6 -28.41732 -55.03171 soybean -5.1542411 -7.344623 -10.879841 2.6003060
## b4_GCVI specie
## 1 -4.631691 Glycine max
## 2 -2.661626 Glycine max
## 3 -2.707749 Glycine max
## 4 -3.352147 Glycine max
## 5 -3.434427 Glycine max
## 6 -7.331731 Glycine max&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="summarise" class="section level1">
&lt;h1>Summarise&lt;/h1>
&lt;div id="summarise-creates-a-new-data-frame." class="section level2">
&lt;h2>&lt;code>summarise&lt;/code> creates a new data frame.&lt;/h2>
&lt;/div>
&lt;div id="the-objective-of-the-function-is-summarise-a-data-frame-for-an-aspect." class="section level2">
&lt;h2>The objective of the function is summarise a data frame for an aspect.&lt;/h2>
&lt;/div>
&lt;div id="the-most-common-functions-used-into-summarise-function-are" class="section level2">
&lt;h2>The most common functions used into &lt;code>summarise&lt;/code> function are:&lt;/h2>
&lt;div id="mean-median" class="section level5">
&lt;h5>&lt;code>mean()&lt;/code>, &lt;code>median()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="sd-iqr-mad" class="section level5">
&lt;h5>&lt;code>sd()&lt;/code>, &lt;code>IQR()&lt;/code>, &lt;code>mad()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="min-max-quantile" class="section level5">
&lt;h5>&lt;code>min()&lt;/code>, &lt;code>max()&lt;/code>, &lt;code>quantile()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="first-last-nth" class="section level5">
&lt;h5>&lt;code>first()&lt;/code>, &lt;code>last()&lt;/code>, &lt;code>nth()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="n-n_distinct" class="section level5">
&lt;h5>&lt;code>n()&lt;/code>, &lt;code>n_distinct()&lt;/code>&lt;/h5>
&lt;/div>
&lt;div id="any-all" class="section level5">
&lt;h5>&lt;code>any()&lt;/code>, &lt;code>all()&lt;/code>&lt;/h5>
&lt;/div>
&lt;/div>
&lt;div id="we-also-may-put-more-than-one-function-in-summarise-function." class="section level2">
&lt;h2>We also may put more than one function in &lt;code>summarise&lt;/code> function.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; summarise(n = n(), min = min(b4_GCVI), max = max(b4_GCVI), mean = mean(b4_GCVI))
## n min max mean
## 1 100 -7.331731 5.124163 -1.386388&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="group-by" class="section level1">
&lt;h1>Group by&lt;/h1>
&lt;div id="group_by-takes-an-existing-data-frame-and-converts-it-into-a-grouped-data-frame-where-operations-are-performed-by-group.-ungroup-removes-grouping." class="section level2">
&lt;h2>&lt;code>group_by&lt;/code> takes an existing data frame and converts it into a grouped data frame where operations are performed by group. ungroup() removes grouping.&lt;/h2>
&lt;/div>
&lt;div id="generally-the-group_by-function-is-used-before-the-summarise-function-to-generate-summaries-by-group." class="section level2">
&lt;h2>Generally the &lt;code>group_by&lt;/code> function is used before the &lt;code>summarise&lt;/code> function to generate summaries by group.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; group_by(class) |&amp;gt; summarise(n = n(), min = min(b4_GCVI), max = max(b4_GCVI), mean = mean(b4_GCVI))
## # A tibble: 2 x 5
## class n min max mean
## &amp;lt;chr&amp;gt; &amp;lt;int&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1 corn 50 -3.33 5.12 1.34
## 2 soybean 50 -7.33 -1.29 -4.11&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="pull" class="section level1">
&lt;h1>Pull&lt;/h1>
&lt;div id="pull-selects-a-column-in-a-data-frame-and-transforms-it-into-a-vector." class="section level2">
&lt;h2>&lt;code>pull&lt;/code> selects a column in a data frame and transforms it into a vector.&lt;/h2>
&lt;/div>
&lt;div id="when-we-are-leading-with-data-wrangling-we-can-use-pull-function-to-extract-columns-as-a-vector." class="section level2">
&lt;h2>When we are leading with data wrangling we can use &lt;code>pull&lt;/code> function to extract columns as a vector.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; pull(b4_GCVI) |&amp;gt; head(6)
## [1] -4.631691 -2.661626 -2.707749 -3.352147 -3.434427 -7.331731&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="join" class="section level1">
&lt;h1>Join&lt;/h1>
&lt;div id="join-function-joins-two-data-frames-together." class="section level2">
&lt;h2>&lt;code>join&lt;/code> function joins two data frames together.&lt;/h2>
&lt;/div>
&lt;div id="joining-tables-data-frames-with-foreign-key-the-by-in-the-join-function-is-the-most-important-for-relational-databases." class="section level2">
&lt;h2>Joining tables, data frames with foreign key, the &lt;code>by&lt;/code> in the &lt;code>join&lt;/code> function is the most important for relational databases.&lt;/h2>
&lt;/div>
&lt;div id="the-types-of-join-are" class="section level2">
&lt;h2>The types of join are:&lt;/h2>
&lt;div id="inner_join-only-rows-with-matching-keys-in-both-x-and-y" class="section level3">
&lt;h3>&lt;code>inner_join&lt;/code> : only rows with matching keys in both x and y;&lt;/h3>
&lt;/div>
&lt;div id="left_join-all-rows-in-x-adding-matching-columns-from-y" class="section level3">
&lt;h3>&lt;code>left_join&lt;/code> : all rows in x, adding matching columns from y;&lt;/h3>
&lt;/div>
&lt;div id="right_join-all-rows-in-y-adding-matching-columns-from-x" class="section level3">
&lt;h3>&lt;code>right_join&lt;/code> : all rows in y, adding matching columns from x;&lt;/h3>
&lt;/div>
&lt;div id="full_join-all-rows-in-x-with-matching-columns-in-y-then-the-rows-of-y-that-dont-match-x." class="section level3">
&lt;h3>&lt;code>full_join&lt;/code> : all rows in x with matching columns in y, then the rows of y that don’t match x.&lt;/h3>
&lt;/div>
&lt;/div>
&lt;div id="you-can-se-the-differences-with-the-below-example." class="section level2">
&lt;h2>You can se the differences with the below example.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; select(ï..n,latitude,longitude,class,b0_GCVI) -&amp;gt; data_1
data |&amp;gt; select(ï..n,latitude,longitude,class,b1_GCVI) -&amp;gt; data_2
data_1 &amp;lt;- data_1[1:60,]
data_2 &amp;lt;- data_2[51:100,]
data_x &amp;lt;- inner_join(data_1,data_2, by = c(&amp;quot;ï..n&amp;quot;,&amp;quot;latitude&amp;quot;,&amp;quot;longitude&amp;quot;,&amp;quot;class&amp;quot;))
data_x |&amp;gt; glimpse()
## Rows: 10
## Columns: 6
## $ ï..n &amp;lt;int&amp;gt; 51, 52, 53, 54, 55, 56, 57, 58, 59, 60
## $ latitude &amp;lt;dbl&amp;gt; -27.93454, -28.12877, -27.89983, -28.43043, -28.58020, -27.7~
## $ longitude &amp;lt;dbl&amp;gt; -52.08487, -51.32797, -54.50413, -51.63524, -51.75654, -51.7~
## $ class &amp;lt;chr&amp;gt; &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;cor~
## $ b0_GCVI &amp;lt;dbl&amp;gt; 4.5186558, 1.2942828, 7.8575535, -2.8303745, -0.2717497, 5.2~
## $ b1_GCVI &amp;lt;dbl&amp;gt; 0.8883052, -2.2323170, 5.9253740, -5.7838035, -3.2403061, 1.~
data_x &amp;lt;- left_join(data_1,data_2, by = c(&amp;quot;ï..n&amp;quot;,&amp;quot;latitude&amp;quot;,&amp;quot;longitude&amp;quot;,&amp;quot;class&amp;quot;))
data_x |&amp;gt; glimpse()
## Rows: 60
## Columns: 6
## $ ï..n &amp;lt;int&amp;gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1~
## $ latitude &amp;lt;dbl&amp;gt; -28.59329, -30.87459, -28.84481, -30.65571, -28.85978, -28.4~
## $ longitude &amp;lt;dbl&amp;gt; -52.64978, -51.72551, -53.46126, -55.11848, -53.61491, -55.0~
## $ class &amp;lt;chr&amp;gt; &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soyb~
## $ b0_GCVI &amp;lt;dbl&amp;gt; -1.48824394, -1.07909429, 0.16900872, -0.92421901, -0.671991~
## $ b1_GCVI &amp;lt;dbl&amp;gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
data_x &amp;lt;- right_join(data_1,data_2, by = c(&amp;quot;ï..n&amp;quot;,&amp;quot;latitude&amp;quot;,&amp;quot;longitude&amp;quot;,&amp;quot;class&amp;quot;))
data_x |&amp;gt; glimpse()
## Rows: 50
## Columns: 6
## $ ï..n &amp;lt;int&amp;gt; 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, ~
## $ latitude &amp;lt;dbl&amp;gt; -27.93454, -28.12877, -27.89983, -28.43043, -28.58020, -27.7~
## $ longitude &amp;lt;dbl&amp;gt; -52.08487, -51.32797, -54.50413, -51.63524, -51.75654, -51.7~
## $ class &amp;lt;chr&amp;gt; &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;corn&amp;quot;, &amp;quot;cor~
## $ b0_GCVI &amp;lt;dbl&amp;gt; 4.5186558, 1.2942828, 7.8575535, -2.8303745, -0.2717497, 5.2~
## $ b1_GCVI &amp;lt;dbl&amp;gt; 0.8883052, -2.2323170, 5.9253740, -5.7838035, -3.2403061, 1.~
data_x &amp;lt;- full_join(data_1,data_2, by = c(&amp;quot;ï..n&amp;quot;,&amp;quot;latitude&amp;quot;,&amp;quot;longitude&amp;quot;,&amp;quot;class&amp;quot;))
data_x |&amp;gt; glimpse()
## Rows: 100
## Columns: 6
## $ ï..n &amp;lt;int&amp;gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1~
## $ latitude &amp;lt;dbl&amp;gt; -28.59329, -30.87459, -28.84481, -30.65571, -28.85978, -28.4~
## $ longitude &amp;lt;dbl&amp;gt; -52.64978, -51.72551, -53.46126, -55.11848, -53.61491, -55.0~
## $ class &amp;lt;chr&amp;gt; &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soybean&amp;quot;, &amp;quot;soyb~
## $ b0_GCVI &amp;lt;dbl&amp;gt; -1.48824394, -1.07909429, 0.16900872, -0.92421901, -0.671991~
## $ b1_GCVI &amp;lt;dbl&amp;gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="unite" class="section level1">
&lt;h1>Unite&lt;/h1>
&lt;div id="unite-function-unites-the-values-of-two-columns-into-one." class="section level2">
&lt;h2>&lt;code>unite&lt;/code> function unites the values of two columns into one.&lt;/h2>
&lt;/div>
&lt;div id="when-we-would-like-to-unite-two-columns-to-use-as-a-merged-column-we-can-use-unite-function." class="section level2">
&lt;h2>When we would like to unite two columns to use as a merged column we can use &lt;code>unite&lt;/code> function.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; unite (&amp;quot;n_class&amp;quot;,ï..n,class,sep=&amp;quot;_&amp;quot;) -&amp;gt; data_united
data_united |&amp;gt; head(6)
## n_class latitude longitude b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 1_soybean -28.59329 -52.64978 -1.4882439 -3.811363 -6.338071 1.2918025
## 2 2_soybean -30.87459 -51.72551 -1.0790943 -1.828730 -4.837896 2.0158091
## 3 3_soybean -28.84481 -53.46126 0.1690087 -2.050998 -2.741627 -1.1819744
## 4 4_soybean -30.65571 -55.11848 -0.9242190 -2.597677 -4.246418 0.8886908
## 5 5_soybean -28.85978 -53.61491 -0.6719911 -2.803353 -4.301278 -0.2094595
## 6 6_soybean -28.41732 -55.03171 -5.1542411 -7.344623 -10.879841 2.6003060
## b4_GCVI
## 1 -4.631691
## 2 -2.661626
## 3 -2.707749
## 4 -3.352147
## 5 -3.434427
## 6 -7.331731&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="separate" class="section level1">
&lt;h1>Separate&lt;/h1>
&lt;div id="separate-function-separates-a-character-column-into-multiple-columns-with-a-regular-expression-or-numeric-locations." class="section level2">
&lt;h2>&lt;code>separate&lt;/code> function separates a character column into multiple columns with a regular expression or numeric locations.&lt;/h2>
&lt;/div>
&lt;div id="when-we-would-like-to-separate-a-column-to-have-two-or-more-columns-we-can-use-the-separate-function" class="section level2">
&lt;h2>When we would like to separate a column to have two or more columns, we can use the &lt;code>separate&lt;/code> function&lt;/h2>
&lt;pre class="r">&lt;code>data_united |&amp;gt; separate(n_class,c(&amp;quot;ï..n&amp;quot;,&amp;quot;class&amp;quot;),sep=&amp;quot;_&amp;quot;) |&amp;gt; head(6)
## ï..n class latitude longitude b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 1 soybean -28.59329 -52.64978 -1.4882439 -3.811363 -6.338071 1.2918025
## 2 2 soybean -30.87459 -51.72551 -1.0790943 -1.828730 -4.837896 2.0158091
## 3 3 soybean -28.84481 -53.46126 0.1690087 -2.050998 -2.741627 -1.1819744
## 4 4 soybean -30.65571 -55.11848 -0.9242190 -2.597677 -4.246418 0.8886908
## 5 5 soybean -28.85978 -53.61491 -0.6719911 -2.803353 -4.301278 -0.2094595
## 6 6 soybean -28.41732 -55.03171 -5.1542411 -7.344623 -10.879841 2.6003060
## b4_GCVI
## 1 -4.631691
## 2 -2.661626
## 3 -2.707749
## 4 -3.352147
## 5 -3.434427
## 6 -7.331731&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="gather" class="section level1">
&lt;h1>Gather&lt;/h1>
&lt;div id="gather-function-gathers-columns-into-key-value-pairs." class="section level2">
&lt;h2>&lt;code>gather&lt;/code> function gathers columns into key-value pairs.&lt;/h2>
&lt;/div>
&lt;div id="when-we-would-like-to-gather-columns-into-two-new-columns-containing-a-specific-column-name-and-the-respectively-column-values-we-can-use-the-gather-function." class="section level2">
&lt;h2>When we would like to gather columns into two new columns containing a specific column name and the respectively column values we can use the &lt;code>gather&lt;/code> function.&lt;/h2>
&lt;pre class="r">&lt;code>data |&amp;gt; gather(key=&amp;quot;Feature&amp;quot;,value=&amp;quot;Value&amp;quot;,b0_GCVI:b4_GCVI) -&amp;gt; data_gathered
data_gathered |&amp;gt; head(6)
## ï..n latitude longitude class Feature Value
## 1 1 -28.59329 -52.64978 soybean b0_GCVI -1.4882439
## 2 2 -30.87459 -51.72551 soybean b0_GCVI -1.0790943
## 3 3 -28.84481 -53.46126 soybean b0_GCVI 0.1690087
## 4 4 -30.65571 -55.11848 soybean b0_GCVI -0.9242190
## 5 5 -28.85978 -53.61491 soybean b0_GCVI -0.6719911
## 6 6 -28.41732 -55.03171 soybean b0_GCVI -5.1542411&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="spread" class="section level1">
&lt;h1>Spread&lt;/h1>
&lt;div id="spread-function-spreads-a-key-value-pair-across-multiple-columns." class="section level2">
&lt;h2>&lt;code>spread&lt;/code> function spreads a key-value pair across multiple columns.&lt;/h2>
&lt;/div>
&lt;div id="when-we-need-to-distribute-the-pair-of-key-value-columns-into-a-field-of-cells-we-can-use-the-spread-function." class="section level2">
&lt;h2>When we need to distribute the pair of key-value columns into a field of cells we can use the &lt;code>spread&lt;/code> function.&lt;/h2>
&lt;pre class="r">&lt;code>data_gathered %&amp;gt;% spread(key = Feature,value = Value) |&amp;gt; head(6)
## ï..n latitude longitude class b0_GCVI b1_GCVI b2_GCVI b3_GCVI
## 1 1 -28.59329 -52.64978 soybean -1.4882439 -3.811363 -6.338071 1.2918025
## 2 2 -30.87459 -51.72551 soybean -1.0790943 -1.828730 -4.837896 2.0158091
## 3 3 -28.84481 -53.46126 soybean 0.1690087 -2.050998 -2.741627 -1.1819744
## 4 4 -30.65571 -55.11848 soybean -0.9242190 -2.597677 -4.246418 0.8886908
## 5 5 -28.85978 -53.61491 soybean -0.6719911 -2.803353 -4.301278 -0.2094595
## 6 6 -28.41732 -55.03171 soybean -5.1542411 -7.344623 -10.879841 2.6003060
## b4_GCVI
## 1 -4.631691
## 2 -2.661626
## 3 -2.707749
## 4 -3.352147
## 5 -3.434427
## 6 -7.331731&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="final" class="section level1">
&lt;h1>Final&lt;/h1>
&lt;div id="here-are-the-most-common-functions-for-data-wrangling-utilizing-tidyverse-package." class="section level3">
&lt;h3>Here are the most common functions for data wrangling utilizing tidyverse package.&lt;/h3>
&lt;/div>
&lt;/div></description></item><item><title>R - Data visualization, linear regression and logistic regression</title><link>https://luanppott.netlify.app/post/post3/</link><pubDate>Thu, 23 Sep 2021 00:00:00 +0000</pubDate><guid>https://luanppott.netlify.app/post/post3/</guid><description>
&lt;script src="https://luanppott.netlify.app/post/post3/index.en_files/header-attrs/header-attrs.js">&lt;/script>
&lt;div id="data-visualization-linear-regression-and-logistic-regression" class="section level1">
&lt;h1>Data visualization, linear regression and logistic regression&lt;/h1>
&lt;div id="crop-data-collection---ground-truth-and-remote-sensing" class="section level2">
&lt;h2>Crop data collection - ground truth and remote sensing&lt;/h2>
&lt;/div>
&lt;div id="loading-the-packages" class="section level2">
&lt;h2>Loading the packages&lt;/h2>
&lt;pre class="r">&lt;code>library(tidyverse)
library(tidymodels)
library(sf)
library(geobr)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="url-link-of-data-from-data-collection-and-remote-sensing-on-github-httpsgithub.comluanpott10class" class="section level2">
&lt;h2>URL link of data from data collection and remote sensing on GitHub &lt;a href="https://github.com/luanpott10/Class" class="uri">https://github.com/luanpott10/Class&lt;/a>&lt;/h2>
&lt;/div>
&lt;div id="you-will-need-the-raw-file-httpsraw.githubusercontent.comluanpott10classmaindata_crops.csv" class="section level2">
&lt;h2>You will need the raw file &lt;a href="https://raw.githubusercontent.com/luanpott10/Class/main/data_crops.csv" class="uri">https://raw.githubusercontent.com/luanpott10/Class/main/data_crops.csv&lt;/a>&lt;/h2>
&lt;/div>
&lt;div id="loading-the-data" class="section level2">
&lt;h2>Loading the data&lt;/h2>
&lt;pre class="r">&lt;code>data &amp;lt;- read.csv(&amp;quot;https://raw.githubusercontent.com/luanpott10/Class/main/data_crops.csv&amp;quot;)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="plot-the-data-in-the-map" class="section level2">
&lt;h2>Plot the data in the map&lt;/h2>
&lt;pre class="r">&lt;code>cities_RS &amp;lt;- read_municipality(code_muni = &amp;quot;RS&amp;quot;, year= 2020)
ggplot()+
geom_sf(data=cities_RS)+
geom_point(data=data,aes(x=longitude,y=latitude,fill=class),shape=22,size=2)+
labs(x= &amp;quot;Longitude&amp;quot;, y = &amp;quot;Latitude&amp;quot;)+
scale_fill_manual(values = c(&amp;quot;#eded0c&amp;quot;, &amp;quot;#49a345&amp;quot;))+
theme(legend.position = c(0.17, 0.2),
panel.border = element_rect(color=&amp;quot;Black&amp;quot;, fill = NA),
panel.background = element_rect(fill = &amp;quot;#f2f2f2&amp;quot;),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
axis.title.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
legend.title = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.text = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.background = element_rect(fill=&amp;quot;#f2f2f2&amp;quot;,
linetype=&amp;quot;dashed&amp;quot;,
colour =&amp;quot;#f2f2f2&amp;quot;))&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post3/index.en_files/figure-html/unnamed-chunk-3-1.png" width="480" />&lt;/p>
&lt;/div>
&lt;div id="plot-the-data-variables---continuous-x-continuous" class="section level2">
&lt;h2>Plot the data variables - continuous x continuous&lt;/h2>
&lt;pre class="r">&lt;code>ggplot(data=data,aes(x=b3_GCVI,y=b4_GCVI))+
geom_point(aes(fill=class),shape=22,size=2)+
scale_fill_manual(values = c(&amp;quot;#eded0c&amp;quot;, &amp;quot;#49a345&amp;quot;))+
stat_smooth(formula = y~x, method=&amp;quot;lm&amp;quot;, se=FALSE,color=&amp;quot;black&amp;quot;, linetype=&amp;#39;dashed&amp;#39;)+
theme(panel.border = element_rect(color=&amp;quot;Black&amp;quot;, fill = NA),
panel.background = element_rect(fill = &amp;quot;#f2f2f2&amp;quot;),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
axis.title.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
legend.title = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.text = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.background = element_rect(fill=&amp;quot;#f2f2f2&amp;quot;,
linetype=&amp;quot;dashed&amp;quot;,
colour =&amp;quot;#f2f2f2&amp;quot;))&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post3/index.en_files/figure-html/unnamed-chunk-4-1.png" width="672" />&lt;/p>
&lt;/div>
&lt;div id="linear-regression" class="section level2">
&lt;h2>Linear regression&lt;/h2>
&lt;pre class="r">&lt;code>lm_fit_x &amp;lt;- lm(b3_GCVI ~ b4_GCVI, data = data)
summary(lm_fit_x)
##
## Call:
## lm(formula = b3_GCVI ~ b4_GCVI, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.7924 -0.9983 -0.0018 0.9525 3.9586
##
## Coefficients:
## Estimate Std. Error t value Pr(&amp;gt;|t|)
## (Intercept) -0.73701 0.15933 -4.626 1.14e-05 ***
## b4_GCVI -0.49793 0.04352 -11.440 &amp;lt; 2e-16 ***
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1
##
## Residual standard error: 1.475 on 98 degrees of freedom
## Multiple R-squared: 0.5718, Adjusted R-squared: 0.5675
## F-statistic: 130.9 on 1 and 98 DF, p-value: &amp;lt; 2.2e-16&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="linear-regression-by-tidymodels-workflow" class="section level2">
&lt;h2>Linear regression by tidymodels workflow&lt;/h2>
&lt;div id="creating-a-parsnip-specification-for-a-linear-regression-model" class="section level4">
&lt;h4>Creating a parsnip specification for a linear regression model&lt;/h4>
&lt;pre class="r">&lt;code>lm_model &amp;lt;- linear_reg() |&amp;gt;
set_engine(&amp;#39;lm&amp;#39;) |&amp;gt;
set_mode(&amp;#39;regression&amp;#39;)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="fitting-the-model-supplying-a-formula-expression-and-the-data" class="section level4">
&lt;h4>Fitting the model supplying a formula expression and the data&lt;/h4>
&lt;pre class="r">&lt;code>lm_fit &amp;lt;- lm_model %&amp;gt;%
fit(b3_GCVI ~ b4_GCVI, data = data)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="summary-of-the-model" class="section level4">
&lt;h4>Summary of the model&lt;/h4>
&lt;pre class="r">&lt;code>lm_fit |&amp;gt;
pluck(&amp;quot;fit&amp;quot;) |&amp;gt;
summary()
##
## Call:
## stats::lm(formula = b3_GCVI ~ b4_GCVI, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.7924 -0.9983 -0.0018 0.9525 3.9586
##
## Coefficients:
## Estimate Std. Error t value Pr(&amp;gt;|t|)
## (Intercept) -0.73701 0.15933 -4.626 1.14e-05 ***
## b4_GCVI -0.49793 0.04352 -11.440 &amp;lt; 2e-16 ***
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1
##
## Residual standard error: 1.475 on 98 degrees of freedom
## Multiple R-squared: 0.5718, Adjusted R-squared: 0.5675
## F-statistic: 130.9 on 1 and 98 DF, p-value: &amp;lt; 2.2e-16
# Also you can use
lm_fit$fit |&amp;gt; summary()
##
## Call:
## stats::lm(formula = b3_GCVI ~ b4_GCVI, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.7924 -0.9983 -0.0018 0.9525 3.9586
##
## Coefficients:
## Estimate Std. Error t value Pr(&amp;gt;|t|)
## (Intercept) -0.73701 0.15933 -4.626 1.14e-05 ***
## b4_GCVI -0.49793 0.04352 -11.440 &amp;lt; 2e-16 ***
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1
##
## Residual standard error: 1.475 on 98 degrees of freedom
## Multiple R-squared: 0.5718, Adjusted R-squared: 0.5675
## F-statistic: 130.9 on 1 and 98 DF, p-value: &amp;lt; 2.2e-16&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="parameter-estimates-of-a-the-lm-object" class="section level4">
&lt;h4>Parameter estimates of a the lm object&lt;/h4>
&lt;pre class="r">&lt;code>tidy(lm_fit)
## # A tibble: 2 x 5
## term estimate std.error statistic p.value
## &amp;lt;chr&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1 (Intercept) -0.737 0.159 -4.63 1.14e- 5
## 2 b4_GCVI -0.498 0.0435 -11.4 9.39e-20&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="extract-the-model-statistics" class="section level4">
&lt;h4>Extract the model statistics&lt;/h4>
&lt;pre class="r">&lt;code>glance(lm_fit)
## # A tibble: 1 x 12
## r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC
## &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1 0.572 0.567 1.47 131. 9.39e-20 1 -180. 365. 373.
## # ... with 3 more variables: deviance &amp;lt;dbl&amp;gt;, df.residual &amp;lt;int&amp;gt;, nobs &amp;lt;int&amp;gt;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="plot-the-data-variables---categorical-x-continuous" class="section level2">
&lt;h2>Plot the data variables - categorical x continuous&lt;/h2>
&lt;pre class="r">&lt;code>data &amp;lt;- data |&amp;gt; mutate(target = case_when(class == &amp;quot;corn&amp;quot; ~ 0,
class == &amp;quot;soybean&amp;quot; ~ 1))
ggplot(data=data, aes(y=target,x=b4_GCVI))+
geom_point(aes(fill=as.factor(target)),shape=22,size=2) +
scale_fill_manual(values = c(&amp;quot;#eded0c&amp;quot;, &amp;quot;#49a345&amp;quot;))+
scale_y_continuous(breaks=c(0,1),
labels=c(&amp;quot;0&amp;quot;,&amp;quot;1&amp;quot;),
limits=c(0,1))+
stat_smooth(formula = y~x, method=&amp;quot;glm&amp;quot;, se=FALSE, method.args = list(family=binomial),
color=&amp;quot;black&amp;quot;, linetype=&amp;#39;dashed&amp;#39;)+
labs(x= &amp;quot;b4_GCVI&amp;quot;, y = &amp;quot;Class&amp;quot;,fill=&amp;quot;Class&amp;quot;)+
theme(legend.position = c(0.17, 0.2),
panel.border = element_rect(color=&amp;quot;Black&amp;quot;, fill = NA),
panel.background = element_rect(fill = &amp;quot;#f2f2f2&amp;quot;),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
axis.title.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
legend.title = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.text = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.background = element_rect(fill=&amp;quot;#f2f2f2&amp;quot;,
linetype=&amp;quot;dashed&amp;quot;,
colour =&amp;quot;#f2f2f2&amp;quot;))&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post3/index.en_files/figure-html/unnamed-chunk-11-1.png" width="480" />&lt;/p>
&lt;/div>
&lt;div id="logistic-regression" class="section level2">
&lt;h2>Logistic regression&lt;/h2>
&lt;pre class="r">&lt;code>lg_fit_x &amp;lt;- glm(as.factor(class) ~ b4_GCVI, family=&amp;quot;binomial&amp;quot;, data=data)
summary(lg_fit_x)
##
## Call:
## glm(formula = as.factor(class) ~ b4_GCVI, family = &amp;quot;binomial&amp;quot;,
## data = data)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.91207 -0.04298 0.01134 0.32227 1.86651
##
## Coefficients:
## Estimate Std. Error z value Pr(&amp;gt;|z|)
## (Intercept) -3.5734 1.1155 -3.203 0.00136 **
## b4_GCVI -1.5677 0.3778 -4.150 3.33e-05 ***
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 138.629 on 99 degrees of freedom
## Residual deviance: 42.379 on 98 degrees of freedom
## AIC: 46.379
##
## Number of Fisher Scoring iterations: 7&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="logistic-regression-by-tidymodels-workflow" class="section level2">
&lt;h2>Logistic regression by tidymodels workflow&lt;/h2>
&lt;div id="creating-a-parsnip-specification-for-a-logistic-regression-model" class="section level4">
&lt;h4>Creating a parsnip specification for a logistic regression model&lt;/h4>
&lt;pre class="r">&lt;code>lg_model &amp;lt;- logistic_reg() |&amp;gt;
set_engine(&amp;quot;glm&amp;quot;) |&amp;gt;
set_mode(&amp;quot;classification&amp;quot;)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="fitting-the-model-supplying-a-formula-expression-and-the-data-1" class="section level4">
&lt;h4>Fitting the model supplying a formula expression and the data&lt;/h4>
&lt;pre class="r">&lt;code>lg_fit &amp;lt;- lg_model |&amp;gt;
fit(as.factor(class) ~ b4_GCVI, data = data)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="summary-of-the-model-1" class="section level4">
&lt;h4>Summary of the model&lt;/h4>
&lt;pre class="r">&lt;code>lg_fit |&amp;gt;
pluck(&amp;quot;fit&amp;quot;) |&amp;gt;
summary()
##
## Call:
## stats::glm(formula = as.factor(class) ~ b4_GCVI, family = stats::binomial,
## data = data)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.91207 -0.04298 0.01134 0.32227 1.86651
##
## Coefficients:
## Estimate Std. Error z value Pr(&amp;gt;|z|)
## (Intercept) -3.5734 1.1155 -3.203 0.00136 **
## b4_GCVI -1.5677 0.3778 -4.150 3.33e-05 ***
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 138.629 on 99 degrees of freedom
## Residual deviance: 42.379 on 98 degrees of freedom
## AIC: 46.379
##
## Number of Fisher Scoring iterations: 7
# Also you can use
lg_fit$fit |&amp;gt; summary()
##
## Call:
## stats::glm(formula = as.factor(class) ~ b4_GCVI, family = stats::binomial,
## data = data)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.91207 -0.04298 0.01134 0.32227 1.86651
##
## Coefficients:
## Estimate Std. Error z value Pr(&amp;gt;|z|)
## (Intercept) -3.5734 1.1155 -3.203 0.00136 **
## b4_GCVI -1.5677 0.3778 -4.150 3.33e-05 ***
## ---
## Signif. codes: 0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 138.629 on 99 degrees of freedom
## Residual deviance: 42.379 on 98 degrees of freedom
## AIC: 46.379
##
## Number of Fisher Scoring iterations: 7&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="parameter-estimates-of-a-the-lm-object-1" class="section level4">
&lt;h4>Parameter estimates of a the lm object&lt;/h4>
&lt;pre class="r">&lt;code>tidy(lg_fit)
## # A tibble: 2 x 5
## term estimate std.error statistic p.value
## &amp;lt;chr&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1 (Intercept) -3.57 1.12 -3.20 0.00136
## 2 b4_GCVI -1.57 0.378 -4.15 0.0000333&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="extract-the-model-statistics-1" class="section level4">
&lt;h4>Extract the model statistics&lt;/h4>
&lt;pre class="r">&lt;code>glance(lg_fit)
## # A tibble: 1 x 8
## null.deviance df.null logLik AIC BIC deviance df.residual nobs
## &amp;lt;dbl&amp;gt; &amp;lt;int&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;int&amp;gt; &amp;lt;int&amp;gt;
## 1 139. 99 -21.2 46.4 51.6 42.4 98 100&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;/div></description></item><item><title>R - Cultivated crop maps in Rio Grande do Sul, Brazil</title><link>https://luanppott.netlify.app/post/post1/</link><pubDate>Wed, 22 Sep 2021 00:00:00 +0000</pubDate><guid>https://luanppott.netlify.app/post/post1/</guid><description>
&lt;script src="https://luanppott.netlify.app/post/post1/index.en_files/header-attrs/header-attrs.js">&lt;/script>
&lt;div id="generate-crop-cultivated-maps" class="section level1">
&lt;h1>Generate crop cultivated maps&lt;/h1>
&lt;div id="crop-plantation-area-from-ibge" class="section level2">
&lt;h2>Crop plantation area from IBGE&lt;/h2>
&lt;/div>
&lt;div id="loading-the-packages" class="section level2">
&lt;h2>Loading the packages&lt;/h2>
&lt;pre class="r">&lt;code>library(readxl)
library(tidyverse)
library(geobr)
library(patchwork)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="url-link-of-data-from-ibge-on-github-httpsgithub.comluanpott10class" class="section level2">
&lt;h2>URL link of data from IBGE on GitHub &lt;a href="https://github.com/luanpott10/Class" class="uri">https://github.com/luanpott10/Class&lt;/a>&lt;/h2>
&lt;/div>
&lt;div id="you-will-nedd-the-raw-file-httpsraw.githubusercontent.comluanpott10classmaintabela1612_1.csv" class="section level2">
&lt;h2>You will nedd the raw file &lt;a href="https://raw.githubusercontent.com/luanpott10/Class/main/tabela1612_1.csv" class="uri">https://raw.githubusercontent.com/luanpott10/Class/main/tabela1612_1.csv&lt;/a>&lt;/h2>
&lt;/div>
&lt;div id="load-the-data-and-data-wrangling" class="section level2">
&lt;h2>Load the data and data wrangling&lt;/h2>
&lt;div id="the-data-downloaded-from-ibge-there-are-metadata-in-the-4-first-lines-that-are-not-intrest-for-us-skip-4." class="section level6">
&lt;h6>The data downloaded from IBGE there are metadata in the 4 first lines that are not intrest for us &lt;code>skip = 4&lt;/code>.&lt;/h6>
&lt;/div>
&lt;div id="also-there-are-info-in-the-last-rows-for-that-we-select-the-497-municipalities-data1497." class="section level6">
&lt;h6>Also, there are info in the last rows, for that we select the 497 municipalities &lt;code>data[1:497,]&lt;/code>.&lt;/h6>
&lt;/div>
&lt;div id="furthermore-the-rows-cities-without-crop-planted-ibge-used---or-instead-input-0-then-we-have-used-case_when-function." class="section level6">
&lt;h6>Furthermore, the rows (cities) without crop planted, IBGE used “-” or “…” instead input 0, then we have used &lt;code>case_when&lt;/code> function.&lt;/h6>
&lt;pre class="r">&lt;code>data &amp;lt;- read_csv(&amp;#39;https://raw.githubusercontent.com/luanpott10/Class/main/tabela1612_1.csv&amp;#39;, skip = 4)
data &amp;lt;- data[1:497,]
colnames(data) &amp;lt;- c(&amp;quot;code&amp;quot;,&amp;quot;city&amp;quot;,&amp;quot;rice&amp;quot;,&amp;quot;corn&amp;quot;,&amp;quot;soybean&amp;quot;)
data &amp;lt;- data |&amp;gt;
mutate(rice_crop = case_when(rice == &amp;quot;...&amp;quot; | rice == &amp;quot;-&amp;quot; ~ 0,
TRUE ~ as.double(rice))) |&amp;gt;
mutate(corn_crop = case_when(corn == &amp;quot;...&amp;quot; | corn == &amp;quot;-&amp;quot; ~ 0,
TRUE ~ as.double(corn))) |&amp;gt;
mutate(soybean_crop = case_when(soybean == &amp;quot;...&amp;quot; | soybean == &amp;quot;-&amp;quot; ~ 0,
TRUE ~ as.double(soybean)))
data &amp;lt;- data |&amp;gt; select(code,city,rice_crop,corn_crop,soybean_crop)&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div id="dataset-of-geobr-package-from-municipalities-of-rio-grande-do-sul-state" class="section level2">
&lt;h2>Dataset of geobr package from municipalities of Rio Grande do Sul state&lt;/h2>
&lt;pre class="r">&lt;code>cities_RS &amp;lt;- read_municipality(code_muni = &amp;quot;RS&amp;quot;, year= 2020)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="ggplot-of-the-cities" class="section level2">
&lt;h2>Ggplot of the cities&lt;/h2>
&lt;pre class="r">&lt;code>ggplot()+
geom_sf(data=cities_RS)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post1/index.en_files/figure-html/unnamed-chunk-4-1.png" width="672" />&lt;/p>
&lt;/div>
&lt;div id="joining-the-ibge-data-and-the-sf-object" class="section level2">
&lt;h2>Joining the IBGE data and the sf object&lt;/h2>
&lt;pre class="r">&lt;code>cities_RS$code_muni &amp;lt;- as.character(cities_RS$code_muni)
data_x &amp;lt;- left_join(cities_RS,data,by= c(&amp;quot;code_muni&amp;quot;=&amp;quot;code&amp;quot;))&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="palettes" class="section level2">
&lt;h2>Palettes&lt;/h2>
&lt;pre class="r">&lt;code>pal_soybean &amp;lt;- c(&amp;#39;#252525&amp;#39;,&amp;#39;#ccece6&amp;#39;,&amp;#39;#99d8c9&amp;#39;,&amp;#39;#66c2a4&amp;#39;,&amp;#39;#41ae76&amp;#39;,&amp;#39;#238b45&amp;#39;,&amp;#39;#006d2c&amp;#39;,&amp;#39;#00441b&amp;#39;)
pal_corn &amp;lt;- c(&amp;#39;#252525&amp;#39;,&amp;#39;#f7ffa8&amp;#39;,&amp;#39;#EFFD5F&amp;#39;,&amp;#39;#FCE205&amp;#39;,&amp;#39;#FCD12A&amp;#39;,&amp;#39;#FFC30B&amp;#39;,&amp;#39;#F9A602&amp;#39;,&amp;#39;#c48302&amp;#39;)
pal_rice &amp;lt;- c(&amp;#39;#252525&amp;#39;,&amp;#39;#caebfc&amp;#39;,&amp;#39;#9ecae1&amp;#39;,&amp;#39;#6baed6&amp;#39;,&amp;#39;#4292c6&amp;#39;,&amp;#39;#2171b5&amp;#39;,&amp;#39;#084594&amp;#39;,&amp;#39;#082954&amp;#39;)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="soybean-map" class="section level2">
&lt;h2>Soybean map&lt;/h2>
&lt;pre class="r">&lt;code>(soybean_map &amp;lt;-
ggplot()+
geom_sf(data=data_x,aes(fill=soybean_crop))+
theme_minimal()+
scale_fill_gradientn(colours=pal_soybean,
limits = c(0,150000),
na.value=&amp;#39;#252525&amp;#39;)+
labs(x= &amp;quot;Longitude&amp;quot;, y = &amp;quot;Latitude&amp;quot;, title = &amp;quot;Soybean&amp;quot;)+
guides(fill=guide_colorbar(title=&amp;quot;Crop area (ha)&amp;quot;,barwidth = 1,barheight = 4,
frame.colour = &amp;quot;black&amp;quot;))+
theme(legend.position = c(0.17, 0.2),
panel.border = element_rect(color=&amp;quot;Black&amp;quot;, fill = NA),
panel.background = element_rect(fill = &amp;quot;#f2f2f2&amp;quot;),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
axis.title.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
legend.title = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.text = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.background = element_rect(fill=&amp;quot;#f2f2f2&amp;quot;,
linetype=&amp;quot;dashed&amp;quot;,
colour =&amp;quot;#f2f2f2&amp;quot;)))&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post1/index.en_files/figure-html/unnamed-chunk-7-1.png" width="480" />&lt;/p>
&lt;/div>
&lt;div id="corn-map" class="section level2">
&lt;h2>Corn map&lt;/h2>
&lt;pre class="r">&lt;code>(corn_map &amp;lt;-
ggplot()+
geom_sf(data=data_x,aes(fill=corn_crop))+
theme_minimal()+
scale_fill_gradientn(colours=pal_corn,
limits = c(0,15000),
na.value=&amp;#39;#252525&amp;#39;)+
labs(x= &amp;quot;Longitude&amp;quot;, y = &amp;quot;Latitude&amp;quot;, title = &amp;quot;Corn&amp;quot;)+
guides(fill=guide_colorbar(title=&amp;quot;Crop area (ha)&amp;quot;,barwidth = 1,barheight = 4,
frame.colour = &amp;quot;black&amp;quot;))+
theme(legend.position = c(0.17, 0.2),
panel.border = element_rect(color=&amp;quot;Black&amp;quot;, fill = NA),
panel.background = element_rect(fill = &amp;quot;#f2f2f2&amp;quot;),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
axis.title.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
legend.title = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.text = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.background = element_rect(fill=&amp;quot;#f2f2f2&amp;quot;,
linetype=&amp;quot;dashed&amp;quot;,
colour =&amp;quot;#f2f2f2&amp;quot;)))&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post1/index.en_files/figure-html/unnamed-chunk-8-1.png" width="480" />&lt;/p>
&lt;/div>
&lt;div id="rice-map" class="section level2">
&lt;h2>Rice map&lt;/h2>
&lt;pre class="r">&lt;code>(rice_map &amp;lt;-
ggplot()+
geom_sf(data=data_x,aes(fill=rice_crop))+
theme_minimal()+
scale_fill_gradientn(colours=pal_rice,
limits = c(0,75000),
na.value=&amp;#39;#252525&amp;#39;)+
labs(x= &amp;quot;Longitude&amp;quot;, y = &amp;quot;Latitude&amp;quot;, title = &amp;quot;Rice&amp;quot;)+
guides(fill=guide_colorbar(title=&amp;quot;Crop area (ha)&amp;quot;,barwidth = 1,barheight = 4,
frame.colour = &amp;quot;black&amp;quot;))+
theme(legend.position = c(0.17, 0.2),
panel.border = element_rect(color=&amp;quot;Black&amp;quot;, fill = NA),
panel.background = element_rect(fill = &amp;quot;#f2f2f2&amp;quot;),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.x = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
axis.title.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 22.0),
axis.text.y = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;quot;#000000&amp;quot;,size = 18.0),
legend.title = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.text = element_text(family = &amp;quot;serif&amp;quot;,
colour = &amp;#39;#000000&amp;#39;,size = 12.0),
legend.background = element_rect(fill=&amp;quot;#f2f2f2&amp;quot;,
linetype=&amp;quot;dashed&amp;quot;,
colour =&amp;quot;#f2f2f2&amp;quot;)))&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post1/index.en_files/figure-html/unnamed-chunk-9-1.png" width="480" />&lt;/p>
&lt;/div>
&lt;div id="crop-maps" class="section level2">
&lt;h2>Crop maps&lt;/h2>
&lt;pre class="r">&lt;code>soybean_map + corn_map + rice_map&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://luanppott.netlify.app/post/post1/index.en_files/figure-html/unnamed-chunk-10-1.png" width="1440" />&lt;/p>
&lt;/div>
&lt;/div></description></item></channel></rss>