Splitting plot pane for different plotting shemes in R - r

I have a technical question therefore I am not producing a code here.I have two plots. One was created using base R and the other one was created with sp package. I want to see those packages splitted into two in a row to make comparisons.
So what should I do? All the functions that I know so far like "par" and "layout" are for designing plotting pane in base R.
Should I convert one plot into base R too? or vice versa
Note: Both plots are maps one is a thematic map like using color fill of a variable in a map. The other one is also a map using a color scheme for quantitative breaks.

Related

How to easily make labels for stacked area charts in R like in D3plus

D3plus automatically shrinks and arranges labels for stacked area plots. Is it possible to do the same in R?
I understand that there is a D3Plus package for R but before I walk through their code, I want to be sure that no one has already created a helper function to do this natively. Here is a link to the D3plus code and below are two examples.

How to symbolize groups separately in a graph (R)

I have a small data set consisting of two columns of data and a column designating which of the two sites the data was taken at. I have used xyplot to sort by groups, but I can't figure out how to alter the symbology of each group separately. I also need to add a regression line, and can only figure out how to do that in plot. What graphics package can give me these features in the same graph?
I have looked into different graphics packages to find one in which I can do everything I need, but I am new to R and am not having much luck.
ggplot2 is your go-to.
Try this:
install.packages('ggplot2')
library(ggplot2)
one=c("A","B","A","B")
two=c(1,2,3,4)
three=c(5,7,8,20)
df<-data.frame(one,two,three)
ggplot(df,aes(x=two,y=three,col=one))+geom_line()

Placing grid tables in R

I want to use grid.table() in an existing plot in R. However I can't locate this table on the right side of my chart. So the thing is:
First of all, I make an histogram of my data:
hist(as.numeric(unlist((vels[counts]))),freq=F,
col="gray",border="black",ylim=c(0,0.15),
xlab=paste(names(vels)[counts]),
main=paste("Weibull fitting",names(vels[counts])))
After that, I have implemented a function that plots in an existing chart the Weibull curve giving both parameters A and K:
plot_weibull(K_value,A_value)
And finally I want to place a data.frame using the grid.table() because it shows the cells in a very pretty form, and you can use italic and bold text in cells.
grid.table(round(values,3),cex=0.75,show.rownames=T,
show.colnames=T,show.hlines=T)
The problem is that this table appears in the center of the device in front of the histogram and the curve, and I want it to be in the right side.
After all, I would like to know a tool that clicking on the graph, I would receive the area under my Weibull curve.
The hist function is base graphics and the grid.table function is grid graphics. The 2 graphics systems do not play nicely together without extra effort (as you have noticed).
The easiest fix is to use the addtable2plot function from the plotrix package rather than grid.table. It may not look the same but it would be simple.
Another option is to use a grid graphics function to create the histogram, such as something from the lattice or ggplot2 packages (both can do histograms), then create a specific viewport using grid graphics functions and use grid.table to put the table into that viewport.
Last, if you really want to mix them then see the gridBase package for ways to mix grid and base graphics.

Can I use shingles from lattice in ggplot2 in R

It is possible to use the shingles to define specific ranges in ggplot2. As far as i understand shingles are a way to generate groups. Can we create such shingles and use them in ggplot2 facet_grid to obtain graphs?
Following up from the comments, ggplot can't draw shingles (in the way lattice draws shingles with special indicators in the strip) and by default doesn't have a means of producing the overlapping groups.
However, I cam across this excellent PDF document which aims to produce a gpplot2 version of every figure in Depayan's excellent Lattice book (Lattice: Multivariate Data Visualization with R).
Page 31 contains a custom function fn() which replicates the behaviour of equal.count(), as far as I can tell, to provide the correct data structure to plot with overlapping shingles. The PDF contains plenty of examples of "shingles" in ggplot that you can play with.
So not sure if this answers the Q - but at least it appears one can fudge ggplot into producing plots that use the shingle concept.

Is there any color pattern that exist in R that can be used to color a graph?

I am wondering if in R there is a per-existing package that can colorate sets inside graph or a package that can generate a list of colors that are not close,
Because I have a graph that have many clusters and I want to color but I don't want to colors to be close.
I have found a nice answer here but I am wondering if there is a per-existing package for
You may also want to check out the package RColorBrewer for other built in color palettes. However, you may run into issues if you need large numbers of colours. There is a nice post on CrossValidated which addresses the large n issue and offers a few nice solutions as well. Specifically, would it make sense to facet your plot based on some large groupings? Do you need to plot all of the items at once? ggplot2 makes it easy to facet based on a column in your data. I'm sure there are equivalent functions in base graphics and lattice, but I'm not as familiar with them.
See the functions rainbow, heat.colors, terrain.colors etc, described in the help pages (?rainbow). These are part of the grDevices package, which is installed by default.

Resources