*Hi guys,*

*I meet a problem of googleVis in R.*

*The following plot is what I want exactly. I can get it by ggplot, but not 
googleVIs. Since I stuck in color setting.*

*Copy and paste the following code, you can run it in R. How you help me 
set the color of googleVis. I am a bit confused of google documents.*

*Best*
*Song*

<https://lh3.googleusercontent.com/-Pfwz_IBY3yg/WkyVdQ0BNcI/AAAAAAAAFVA/2tEcfh4mqUoinBaxooSGNyNpwUx8LYKoACLcBGAs/s1600/data_sources.png>

da <- read.csv("/Users/song/Downloads/da.csv", header = TRUE, sep = ";") da 
<- dput(da) #> structure(list(data_source = structure(c(3L, 6L, 1L, 5L, 4L, #> 
7L, 2L, 8L, 9L), .Label = c("arXiv", "engineering.com", "EPO", #> 
"Foerderkatalog", "Fraunhofer Publica", "newatlas.com", 
"opcconnect.opcfoundation.org", #> "phys.org", "theengineer.co.uk"), class 
= "factor"), data_type = structure(c(3L, #> 2L, 4L, 4L, 1L, 2L, 2L, 2L, 
2L), .Label = c("FUNDING_PROJECT", #> "NEWS", "PATENT", 
"SCIENT_PUBLICATION"), class = "factor"), count = c(1253L, #> 656L, 297L, 
26L, 24L, 3L, 2L, 1L, 1L)), .Names = c("data_source", #> "data_type", 
"count"), class = "data.frame", row.names = c(NA, #> -9L)) plotData <- da 
library(ggplot2) library(dplyr) # plotData <- da %>% # arrange(count) %>% # 
mutate( # data_source = factor(data_source, levels = data_source), # 
data_type = factor(data_type, levels = c("FUNDING_PROJECT", # 
"SCIENT_PUBLICATION", # "PATENT","NEWS")) ) plotData[["data_source"]] <- 
factor(plotData$data_source, levels = arrange(plotData 
,plotData$count)$data_source) # Make cVal column a factor with specified 
levels plotData[["data_type"]] <- factor(plotData[["data_type"]], levels = 
c( "FUNDING_PROJECT", "SCIENT_PUBLICATION", "PATENT", "NEWS")) # Initialise 
ggplot p <- ggplot(plotData) # Plot bar chart p <- p + geom_bar(aes_q(x = 
as.name("data_source"), y = as.name("count"), fill = as.name("data_type")), 
stat = "identity", position = position_dodge()) # Add values as labels on 
bars plotData <- cbind(plotData, yLabel = paste0(" ", plotData[,"count"], " 
")) p <- p + geom_text(data = plotData, aes_q(x = as.name("data_source"), y 
= as.name("count"), label = as.name("yLabel"), hjust = "inward"), size = (5/
14)*12 # conversion from mm to px ) # Assign colours to data types p <- p + 
scale_fill_manual(name = "", values = c( "FUNDING_PROJECT" = "red", 
"SCIENT_PUBLICATION" = "blue", "PATENT" = "green", "NEWS" = "black"), 
labels = c( "FUNDING_PROJECT" = "Funded projects", "SCIENT_PUBLICATION" = 
"Scientific 
publications", "PATENT" = "Patents", "NEWS" = "News")) # Flip coordinates p 
<- p + coord_flip() plot(p)

da <- read.csv("/Users/song/Downloads/da.csv", header = TRUE, sep = ";") da 
<- dput(da) #> structure(list(data_source = structure(c(3L, 6L, 1L, 5L, 4L, #> 
7L, 2L, 8L, 9L), .Label = c("arXiv", "engineering.com", "EPO", #> 
"Foerderkatalog", "Fraunhofer Publica", "newatlas.com", 
"opcconnect.opcfoundation.org", #> "phys.org", "theengineer.co.uk"), class 
= "factor"), data_type = structure(c(3L, #> 2L, 4L, 4L, 1L, 2L, 2L, 2L, 
2L), .Label = c("FUNDING_PROJECT", #> "NEWS", "PATENT", 
"SCIENT_PUBLICATION"), class = "factor"), count = c(1253L, #> 656L, 297L, 
26L, 24L, 3L, 2L, 1L, 1L)), .Names = c("data_source", #> "data_type", 
"count"), class = "data.frame", row.names = c(NA, #> -9L)) library(googleVis) 
#> 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. #> 


-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/ee77d569-a1ef-4fbd-a5dc-71969bc7376e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to