Help:Drawing graphs: Difference between revisions
(→Google charts: saving eps and pdf files also added) |
|||
Line 132: | Line 132: | ||
===Google charts=== | ===Google charts=== | ||
This is how you can make fancy Google motion or map charts. See documentation for R package googleVis and [https://developers.google.com/chart/interactive/docs/gallery/motionchart Google's help]. | This is how you can make fancy Google motion or map charts. See documentation for R package googleVis and [https://developers.google.com/chart/interactive/docs/gallery/motionchart Google's help]. Note that Google has copyright in its maps, but the license to use them is very flexible and in practice free [https://developers.google.com/maps/documentation/staticmaps/?csw=1#Limits]. | ||
<rcode name='gvistest' embed=1> | <rcode name='gvistest' embed=1> | ||
Line 149: | Line 149: | ||
</rcode> | </rcode> | ||
=== Export a graph to EPS or PDF file === | |||
This code only works on your own computer, because you cannot save files when running code in Opasnet. [http://stackoverflow.com/questions/5142842/export-a-graph-to-eps-file-with-r] | |||
<pre> | |||
# Saving an .eps file | |||
setEPS() | |||
postscript("whatever.eps") | |||
plot(rnorm(100), main="Hey Some Data") | |||
dev.off() | |||
# Saving a .pdf file | |||
pdf("whatever.pdf") | |||
plot(rnorm(100), main="Hey Some Data") | |||
dev.off() | |||
</pre> | |||
If you are using ggplot2 to generate a figure, then a | |||
<pre> | |||
ggsave(file="name.eps", width = 7, height = 7) | |||
</pre> | |||
will also work. It will save the last ggplot with the width and height you give (in inches). | |||
===Maps and GIS-based data=== | ===Maps and GIS-based data=== |
Revision as of 19:45, 9 March 2015
Moderator:Jouni (see all) |
|
Upload data
|
Question
How to draw graphs in Opasnet?
Answer
R-tools
In R-tools, you have the functionalities of R available. We recommend that you use the package ggplot2 whenever possible. It is very powerful, and borrowing good ideas from others is easier if we all use the same approach. Of course, it is also possible to use plot' (a kind of basic graph) as well, but the limits come sooner. This is an example code that contains all kinds of examples with comments.
rlnorm
- Graph for cumulative probability distributions
Colours and ordering of bars
Google charts
This is how you can make fancy Google motion or map charts. See documentation for R package googleVis and Google's help. Note that Google has copyright in its maps, but the license to use them is very flexible and in practice free [1].
Export a graph to EPS or PDF file
This code only works on your own computer, because you cannot save files when running code in Opasnet. [2]
# Saving an .eps file setEPS() postscript("whatever.eps") plot(rnorm(100), main="Hey Some Data") dev.off() # Saving a .pdf file pdf("whatever.pdf") plot(rnorm(100), main="Hey Some Data") dev.off()
If you are using ggplot2 to generate a figure, then a
ggsave(file="name.eps", width = 7, height = 7)
will also work. It will save the last ggplot with the width and height you give (in inches).
Maps and GIS-based data
There are several methods to produce maps. These are described on Opasnet map.
GoogleDocs
GoogleDocs is the method of choice for drawing causal diagrams.
- Make a drawing.
- Share it with everyone with open editing.
- Download is in png or svg format.
- Upload the file to Opasnet and copy a link to the original Google document to the image page.
- Use like any image.
Sankey diagrams
There is no established approach to Sankey diagrams. A few packages provide with functionalities, but the usebility and user-friendliness has not been tested.
- Harvard tagteam: rCharts R bloggers
- Aaronberdanier: SankeyR function
- Riverplot (and SankeyR?)
- General Sankey diagram website
See also
- Double dots in a ggplot
- Visualising distributions
- Plotting means and error bars
- Cookbook for R: Scatterplots
- Scales of x and y axes
- Add a smoothed conditional mean
- theme_grey
- Different histograms
- Scale and flip graphs with coord_cartesian. Note that coord_flip() can take coord_cartesian() parameters.
- Parameters for geom_density (adjust, fill,...)