pacotes <- c("plotly","tidyverse","ggrepel","reshape2", "PerformanceAnalytics",
"ggplot2")
if(sum(as.numeric(!pacotes %in% installed.packages())) != 0){
instalador <- pacotes[!pacotes %in% installed.packages()]
for(i in 1:length(instalador)) {
install.packages(instalador, dependencies = T)
break()}
sapply(pacotes, require, character = T)
} else {
sapply(pacotes, require, character = T)
}
## Loading required package: plotly
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Loading required package: ggrepel
##
## Loading required package: reshape2
##
##
## Attaching package: 'reshape2'
##
##
## The following object is masked from 'package:tidyr':
##
## smiths
##
##
## Loading required package: PerformanceAnalytics
##
## Loading required package: xts
##
## Loading required package: zoo
##
##
## Attaching package: 'zoo'
##
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
##
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
##
## Attaching package: 'xts'
##
##
## The following objects are masked from 'package:dplyr':
##
## first, last
##
##
##
## Attaching package: 'PerformanceAnalytics'
##
##
## The following object is masked from 'package:graphics':
##
## legend
## plotly tidyverse ggrepel
## TRUE TRUE TRUE
## reshape2 PerformanceAnalytics ggplot2
## TRUE TRUE TRUE
# Crear el data frame ampliado
datos_agronomia <- data.frame(
Cultivo = c("Maíz", "Trigo", "Soja", "Arroz"),
Producción = c(130, 70, 80, 120)
)
datos_agronomia
## Cultivo Producción
## 1 Maíz 130
## 2 Trigo 70
## 3 Soja 80
## 4 Arroz 120
ggplot(datos_agronomia, aes(x = Producción, y = reorder(Cultivo, Producción), fill = Cultivo)) +
geom_bar(stat = "identity") + geom_text(aes(label = Producción), hjust = -0.2) +
labs(title = "Rendimiento de cuatro cultivos en Nariño", subtitle = "Cultivos en Nariño",
x = "Rendimiento (tn/ha)",
y = "Tipos de cultivos (Cultivo)",
caption = "Período: 2021") +
scale_fill_manual(values = c("Maíz" = "blue", "Trigo" = "purple", "Soja" = "brown", "Arroz" = "gray")) +
theme_minimal()
