I am struggling with trying to link the plotly map with a timeline graph.
Below is a sample code that I have modified with my own data. I have taken the code from this link: https://plotly.com/r/choropleth-maps/
df <- read.csv(“https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv”)
df$hover <- with(df, paste(state, ‘
’, “Beef”, beef, “Dairy”, dairy, “
“Fruits”, total.fruits, “Veggies”, total.veggies,
”, “Wheat”, wheat, “Corn”, corn))
l <- list(color = toRGB(“white”), width = 2)
g <- list(
scope = ‘usa’,
projection = list(type = ‘albers usa’),
showlakes = TRUE,
lakecolor = toRGB(‘white’)
fig <- plot_geo(df, locationmode = ‘USA-states’)
fig <- fig %>% add_trace(
z = ~total.exports, text = ~hover, locations = ~code,
color = ~total.exports, colors = ‘Purples’
fig <- fig %>% colorbar(title = “Millions USD”)
fig <- fig %>% layout(
title = ‘2011 US Agriculture Exports by State
(Hover for breakdown)’,
geo = g
The above code doesn’t contain year data but the data that I am using has a YEAR column. I have given the above code for reference since I modified the above code to suit my requirements.
The output that I want to see is, once I click on a particular state, a timeline graph should pop up on the side which will provide the line graph for the selected state with YEAR on the x axis and coverage (in my data, it is coverage) on the y axis.
If someone could help provide a sample code that could do this, it would be great. I know it can be done using plotly.
Thanks in advance.