user2868104
user2868104

Reputation: 297

how to make googlevis plots fit the screen automatically in R

I am trying to make a chart in R via googleVis. How do you make the chart automatically fit the size of the screen, or rather, the browser?

library('googleVis')
Column <- gvisColumnChart(df,
                          options=list(legend='none'))
plot(Column)
cat(createGoogleGadget(Column), file="columnchart.xml")

Upvotes: 4

Views: 1341

Answers (1)

micstr
micstr

Reputation: 5206

It is not very clear from documentation, who seems to want you to use pixels, say width = 200 in pixels, but you can use the word "automatic" which scales nicely.

So snippet from one of my functions:

 # where plotdt has my data with columns px and py
 plot1 <- gvisBarChart(plotdt, 
                       xvar = px,
                       yvar = c(py),
                       options = list(width = "automatic",
                                      height = "automatic")

Note in your case, add to your option list

gvisColumnChart(df,
                options=list(legend='none',
                             width = "automatic",
                             height = "automatic"))

Hope this helps others.

Plus, useful link for more on configuration options. This is for bar charts, so choose the right chart/table type for you on left of page.

TEST IT

Since there is no data above in df for those who want to play with this:

library('googleVis')

# some test data, add your own
df <- data.frame(x = c(1,2,3), 
                 y = c(2,4,6))

plotdata <- gvisColumnChart(df,
                            options=list(legend='none',
                                         width = "automatic",
                                         height = "automatic"))

plot(plotdata)

Upvotes: 2

Related Questions