I'm trying to draw a zip code level choropleth using the choroplethrZip package, and Plotly to get hover text/tooltips. choroplethrZip plots are ggplot2 objects, so I can make a zip code choropleth using the zip_choropleth function, and then use the ggplotly() function of plotly to render a choropleth where the pre-defined bins are the hover text. I'd like for the hover text to be the "region" column in my data frame, as well as the "value" column. The tooltip argument of ggplotly displays the aesthetic mappings, but choroplethrZip doesn't let me specify those. I tried adding them by using
+geom_blank(aes(text=region))
, but I get the same result, the hover text is just the bin that the zip belongs to.
Example code:
library(choroplethrZip)
library(choroplethr)
library(choroplethrMaps)
library(plotly)
library(ggplot2)
df <- get_zip_demographics(endyear= 2013, span=5)
colnames(df)[2] <- c("value")
zipplot <- zip_choropleth(df, state_zoom = "alabama")
ggplotly(zipplot)
Edited to add a library necessary for the code example to work. Also, the choroplethrZip package isn't on CRAN, so here is a link with installation instructions:
https://github.com/arilamstein/choroplethrZip
Related
I want to create a map using the library tmap (to save loads of bother with shapefiles).
Then I convert into leaflet, with a drop down menu to select which data I want to show.
In the example below, I wish for a select option to show either HPI and pop_est instead of World. I have managed to do this but I have not worked out how to have it show it only shows one by default (i.e HPI)
#Load libraries
library(tmap)
library(leaflet)
#Load Data
data("World")
#Create Tmap object
HPI<-tm_shape(World2,name="HPI") +
tm_polygons("HPI",alpha=0.5)
Pop<-tm_shape(World2,name="Pop") +
tm_polygons("pop_est",alpha=0.5)
#Convert to leaflet
lf<-tmap_leaflet(c(HPI,Pop))
#Print leaflet map
lf
I'm learning DataExplorer package in R. I'm using following R code
install.packages('DataExplorer')
library('DataExplorer')
choco=read.csv('flavors_of_cacao.csv',header = T,stringsAsFactors = T)
str(choco)
choco$Cocoa.Percent=as.numeric(gsub('%','',choco$Cocoa.Percent))
choco$Review.Date=as.character(choco$Review.Date)
#checking the dimension of the input dataset and the time of variables.
plot_str(choco)
I'm getting following plot.
I would like to make output of plot_str() visually more appealing so that I can put it in power point presentation.For example text should be bold with color. Can you suggest me how to do that?
Have you tried this?
plot_str(choco, fontSize = 40)
If you look at ?plot_str, the ... passes arguments directly to diagonalNetwork() and radialNetwork() from networkD3 library. You should be able to customize your charts directly.
I’ve been using the dygraphs R package to produce some wonderful timeseries plots, but am having great difficulty reproducing the examples located here:
http://rstudio.github.io/dygraphs/gallery-custom-plotters.html
I’m particularly interested in creating a stacked bar chart:
My data is an xts/zoo object and plots nicely using the standard dygraph function:
However, I am unsure where the dyStackedBarGroup function comes from. It appears these functions must be created, and point to the specific plotters in .js files.
I can see for the first example, how dyBarChart is created, but there is no stackedbarchar.js/stackedbargroup.js in my local dygraph installation (however I can see the file in https://github.com/rstudio/dygraphs/tree/master/inst/plotters).
I’ve attempted to source all the functions and .js files from the github page which do not appear to be made available when loading the dygraphs package locally, but I remain unsuccessful.
Am I doing something completely wrong?
set stackedGraph argument in dyOptions to TRUE. dyOptions(stackedGraph = TRUE).
The javascript file for the barchart can be found at "examples/plotters/barchart.js" of the dygraphs package directory.
Data:
lungDeaths <- cbind(mdeaths, ldeaths)
Code:
# create dygraph plotter
library('dygraphs')
dyBarChart <- function(dygraph) {
dyPlotter(dygraph = dygraph,
name = "BarChart",
path = system.file("examples/plotters/barchart.js", package = "dygraphs"))
}
dygraph(lungDeaths) %>% # create dygraph of lungDeaths
dyBarChart() %>% # create bar chart with the passed dygraph
dyOptions(stackedGraph = TRUE) # make it as stacked bar chart
I am trying to add a "hover" features that shows the name of the country plotted in a symbols plot in an R Shiny app. Most of the guidance on the internet is for ggplot. Can "hover" be added to a regular symbols plot?
output$info <- renderText({
≠paste0("Country =", input$plot_click)
})
This is what I have after my symbols plots in the server section of my code. However, it does not bring up the country name though.
Your example might refer to Interactive plots, you can refer to shiny::runGitHub('shiny-examples/118-highcharter-births/').
I'm looking to import a Google API static map into R using the GetMap function of the RGoogleMaps package. I then plan to plot data points onto the graph in R using PlotOnStaticMap. I would like to use the "terrain" maptype, but don't want the labels on it. I have found a previous stackoverflow question that addresses how to remove the labels on the map by using "style=feature:all|element:labels|visibility:off".
Map with labels: (http://maps.googleapis.com/maps/api/staticmap?center=29.4,-89.2&zoom=9&size=600x500&maptype=terrain&sensor=false)
Map without labels: (http://maps.googleapis.com/maps/api/staticmap?center=29.4,-89.2&zoom=9&size=600x500&maptype=terrain&sensor=false&style=feature:all|element:labels|visibility:off)
This second code produces the exact map I would like. However, when I save it as a PNG file and then go to import it into R using the GetMaps function, it gives me the original map with all the labels still attached.
Does anyone know how I can get the map without labels imported correctly into R? It seems like it shouldn't be that hard, but I haven't been able to come up with a solution.
Thanks!
Codes in R:
smap<-read.table("D:/sediment/Rfiles/smap.txt", header=TRUE, sep= "");
library(RgoogleMaps)
library(rgdal)
MyMap <- GetMap(center=c(29.4, -89.2), zoom=9,
destfile = "D:/sediment/Rfiles/map.png", maptype="terrain")
map<-PlotOnStaticMap(MyMap, lat=smap$lat, lon=smap$lon,
col=c('black'), add=F,cex=1.1,pch=19)
*smap is a data file of lat, lon coordinates to be plotted on the map
Like this?
MyMap <- GetMap(center=c(29.4, -89.2), zoom=9,
destfile = "D:/sediment/Rfiles/map.png", maptype="terrain",
path = "&style=feature:all|element:labels|visibility:off")