I would like to combine different plots in ggplot with grid.arrange. I have data from two different groups that performed a different number tasks in an experiment. One group performed 2 tasks and the other group 4 tasks. I would like to plot the median response times of each group per task, and then combine these plots with the help of grid.arrange (via the command grid.arrange(plot1,plot2, ncol=2)) into one image (see image). The problem is now that the width of the left plot in the image is not the same as the width at the right plot in the image. Is there a way to specify the width of the plots in either ggplot or grid.arrange? I know this might be possible with the "cowplot" package in R but some reason I cannot install this package into my version (version 3.2.2 of Rstudio).
These are the two plots
Related
I have this problem where R will auto-adjust the size of the facets in ggplot. In the 2 attached images, clearly, the one scaled from 0-100 on the y-axis is less stretched out compared to the one scaled at 6.6-7.2. These are plotted using the same ggplot commands from maaply, so I don't know where the difference would come from. Is there any way to prevent R from performing the auto-adjusting to keep the formatting of each ggplot the same? My OCD and I thank you.
It looks like I have made a copy and paste error where I used some the the wrong variable to set the base_height in save_plot within mapply, so the scaling factor was varying across iterations.
I was wondering if you could help me with something.
I'm currently writing some papers with regression analyses (and scatter plots with fitted lines). I'd like to merge all my plots into a single panel as shown.
I've already stacked some plots using grid.arrange from gridExtra (which go in box A), but I have no clue how to:
Create boxes A, B, C, (...), each with its own letter on the top-left corner. Each box contains stacked plots (2 or 3 rows depending on the # of models, with all plots for a single model on the same row) linear regression plots.
Place color labels on top of the boxes (e.g Social Cognition and Moral Judgement)
Place vertical text (which would serve as the Y label) such as Risk Perception and Impact Estimation
Thank you very much
This is the referenced layout
You can plot multiple charts within the same chart area. You can do this with the standard graphics functions by setting the mfcol parameter for a device. For example, to plot six figures within the plot area in three rows of two columns, you would set mfcol as follows:
par(mfcol=c(3, 2))
Each time a new figure is plotted, it will be plotted in a different row or column within the device, starting with the top-left corner.
So you can use plot or ggplot or another plotting package and the plot will be added to the layer.
How can I force wireframe panels to produce single plots instead of one panel plot/grid plot? The reason is that if I have to produce a Sweave/ Pdf File the original wireframe plot, which R produces and which you can see in my other post
Faceted Lattice Plots in R, e.g., wireframes: How to remove strips and add 1-Line subtitles.
will look very small, especially if I have many many single wireframe plots. I can handle single plots more easily in Sweave.
Lattice allows you to specify the number of columns and rows for the plots which then spill over onto adjacent pages if a multi-page device is used:
pdf("nine.pdf", onefile=TRUE, paper="special")
wireframe(pred~Sepal.Width+Petal.Width|interaction(Species,Petal.Length),
pd, drape=FALSE,scale=list(arrows=FALSE), subset=(Species=="setosa"),
layout=c(1,1,9))
dev.off()
On the console device they create new plots which stack up in the plot device and you can "scroll-back" with keystrokes that may vary depending on your unstated OS. The eps format is accessible using directions in ?ps.
I use R and ggplot2 to produce graphs for my thesis. I can port them to tikz objects using the tikzdevice or to a pdf using the pdf device very easily, and in each case, specifying the width and height of the overall plot is straightforward.
However, I am actually more interested in specifying the width of the plot AREA (ie the inner box), since differences in this (particularly for plots on the same page) are more easily detected by the eye, even if they are a couple of points different in the final document.
Of course, the source of this issue can be easily put down to the axis labels that vary depending on the content.
My question is, How can I define 'fixed' axis label widths as a global option, or define the width to be exported as the inner plotting area for ggplot2 objects....
Using R I would like to replace the points in a 2d scatter plot by a pie chart displaying additional values.
The rational behind is that I have time series data for hundreds of elements (proteins) derived from a biological experiment monitored for 4 conditions. I would like to plot the elements (categorial data) on the y axis and occurrence of a event in time on the x axis. To visualize the relative occurrence between the 4 conditions I would like to visualize this in form of a pie chart or doughnut chart overplayed onto the respective point in the scatter plot.
The overall data density is low so overlapping won't be an issue.
Is this possible in R?
I was thinking of using a manual scale in ggplot2 but could not figure out how to define a pie chart as a scale.
Also of interest would be how to best cluster this data and sort it accordingly.
Yes. pieGlyph() is one ready-to-go function from the Rgraphviz package.
Also, I would check out this Q/A for how to do things like this more generally:
How to fill a single 'pch' point on the plot with two-colours?
Especially check out ?my.symbols from the TeachingDemos package.
Lastly, in regards to ggplot2, you should check out this blog post about possible upcoming features:
http://blog.revolutionanalytics.com/2011/10/ggplot2-for-big-data.html
See also Paul Murrell. Integrating grid graphics output with base graphics output. R News, 3(2):7-12, October 2003. http://www.r-project.org/doc/Rnews/Rnews_2003-2.pdf
The code on pp 10-11 sets up the main plot axes, labels and legend, and then opens a series of smaller windows centered at each individual point on the plot and plots a small graph in each window. I've tried pie charts, mosaics and barplots, but the method is not limited to these types.