Last active
June 15, 2019 16:30
-
-
Save gonzalezgouveia/459a2079bf136341e332cabcf64ad698 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Empieza el código # | |
##################### | |
# intalar paquete (si no los tienes) | |
install.packages('tidiverse') | |
install.packages('trelliscopejs') | |
# cargar estas librerias | |
library(tidyverse) | |
library(trelliscopejs) | |
# cargar estos datos directamente desde github | |
vinos <- readr::read_csv("https://bit.ly/2Xih8GX") | |
# limpiando un poco los datos para poder trabajar | |
datos_limpios <- vinos %>% | |
select(pais, puntos, precio) %>% | |
drop_na() %>% # quitando los nulos | |
group_by(pais) %>% | |
filter(n()>2000) %>% # filtrando | |
ungroup() %>% | |
mutate(log_price = log(precio)) # log price | |
# crea una carpeta donde guardar los archivos de trelliscope | |
path_trelliscope <- "./trelliscope/" | |
# creando html de trelliscope, si tienes un error con | |
# el encoding uft8 mira una posible solución más abajo | |
ggplot(datos_limpios, | |
aes(x=log(precio), y=puntos)) + | |
geom_point() + | |
geom_smooth(method=lm, se = FALSE) + | |
facet_trelliscope(~ pais, nrow = 1, ncol = 3, | |
path = path_trelliscope, | |
self_contained=TRUE) | |
# Si generaste el HTML, genial, ahora sabes un poco más! | |
# Házmelo saber comentando un emoji de una piña! | |
# Quiero saber cuanta gente lee este código | |
# y dejar locos a los que no entiendan las piñas xD | |
# REGRESA AL TWEET --> https://bit.ly/2wWTels | |
#--------------------------------------------- | |
# Si tuviste problemas con le encoding revisa | |
# cual tienes con esta funcion | |
getOption("encoding") # "native.enc" | |
# Para que funcione tiene que ser uft8, si el tuyo es | |
# diferente puedes cambiarlo con esta linea de codigo | |
# fuente https://github.com/chgrl/leafletR/issues/25 | |
options(encoding = "utf8") | |
# y listo ahora vuelve a correr la linea 27 de ggplot... | |
# fin del código | |
# Sigueme @GonzalezGouveia --> https://bit.ly/2WkLmFb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment