library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.4.2
library(googleVis)
## Warning: package 'googleVis' was built under R version 3.4.2
## Creating a generic function for 'toJSON' from package 'jsonlite' in package 'googleVis'
##
## Welcome to googleVis version 0.6.2
##
## Please read Google's Terms of Use
## before you start using the package:
## https://developers.google.com/terms/
##
## Note, the plot method of googleVis will by default use
## the standard browser to display its output.
##
## See the googleVis package vignettes for more details,
## or visit http://github.com/mages/googleVis.
##
## To suppress this message use:
## suppressPackageStartupMessages(library(googleVis))
library(datasets)
library(gudatavizfa17)
bcities=bcities
bcities$Bars.Population=100000*bcities$Bars/bcities$Population
bcities$Restaurants.Population=100000*bcities$Restaurants/bcities$Population
bcities$Museums.Population=100000*bcities$Museums/bcities$Population
bcities$Libraries.Population=100000*bcities$Libraries/bcities$Population
bcities$Pro.Sports.Teams.Population=100000*bcities$Pro.Sports.Teams/bcities$Population
bcities$Colleges.Population=100000*bcities$Colleges/bcities$Population
bcitiesgather1=gather(bcities, "Category", "Value", c(16,17))
## Warning in if (!is.finite(x)) return(FALSE): the condition has length > 1
## and only the first element will be used
ggplot(bcitiesgather1,aes(Rank,Value, fill=Rank))+geom_line(stat="identity")+
facet_wrap(~Category)

bcitiesgather2=gather(bcities, "Category", "Value", c(18,19))
## Warning in if (!is.finite(x)) return(FALSE): the condition has length > 1
## and only the first element will be used
ggplot(bcitiesgather2,aes(Rank,Value, fill=Rank))+geom_line(stat="identity")+
facet_wrap(~Category)

bcitiesgather3=gather(bcities, "Category", "Value", c(20,21))
## Warning in if (!is.finite(x)) return(FALSE): the condition has length > 1
## and only the first element will be used
ggplot(bcitiesgather3,aes(Rank,Value, fill=Rank))+geom_line(stat="identity")+
facet_wrap(~Category)

bcitiesgather4=gather(bcities, "Category", "Value", c(14,15))
## Warning in if (!is.finite(x)) return(FALSE): the condition has length > 1
## and only the first element will be used
ggplot(bcitiesgather4,aes(Rank,Value, fill=Rank))+geom_line(stat="identity")+
facet_wrap(~Category)

bcitiesgather5=gather(bcities, "Category", "Value", c(11,13))
## Warning in if (!is.finite(x)) return(FALSE): the condition has length > 1
## and only the first element will be used
ggplot(bcitiesgather5,aes(Rank,Value, fill=Rank))+geom_line(stat="identity")+
facet_wrap(~Category)

ggplot(bcities,aes(Rank, Population))+geom_line(group="Rank")+geom_point()

ggplot(bcities,aes(Rank, Park.acres.per.1000.residents))+geom_line(group="Rank")+geom_point()

ggplot(bcities,aes(Rank, Median.household.income))+geom_line(group="Rank")+geom_point()

Geo <- gvisGeoChart(bcities, locationvar="City",colorvar="Rank", options=list(region="US", height=350, displayMode="markers", colorAxis="{values:[1, 17, 34, 50], colors:[\'red', \'pink\', \'orange',\'green']}") )
Geo
bcities$State=c("California", "Alaska", "Nebraska", "Missouri", "Ohio", "Virgina", "Arizona", "Arizona", "Nevada", "Texas", "Virgina", "North Carolina", "Oklahoma", "Indiana", "Colorado", "Florida", "Nebraska", "California", "New York", "California", "Texas", "Maryland", "Illinois", "Virgina", "Wisconsin", "Kentucky", "Pennsylvania", "Oklahoma", "Texas", "Ohio", "Ohio", "Hawaii", "North Carolina", "Wisconsin", "Georgia", "Missouri", "Lousiana", "Tennessee", "Minnesota", "Pennsylvania", "Minnesota", "California", "Texas", "New York", "Colorado", "Oregon", "Massachusetts", "DC", "Washington", "California")
bcitiescount=bcities%>%group_by(State)%>%summarize(number=length(State))
GeoStates <- gvisGeoChart(bcitiescount, "State", "number",
options=list(region="US", displayMode="regions", resolution="provinces",
width=600, height=400))
GeoStates