Layered Counts: Plot Plot and Spaghetti Plot

I am trying to create multiple charts in one panel. I hope for a box on both sides of the spaghetti patch.

This is an example of my code:

par(mfrow=c(1,3)) boxplot(h~y,dat, xlab="Y", ylab="Incidence 1 (percent)", main="H", scales=list(x=list(at=c(1,2)))) xyplot(H~Yr,groups=Subject,type="b",data=data, ylab="Incidence (percent)", xlab="Year", main="Incidence", scales=list(x=list(at=c(1,2)))) boxplot(h1~y1,dat1, xlab="Y", ylab="Incidence 2 (percent)", main="R", scales=list(x=list(at=c(1,2)))) 

When I draw my first plot, everything looks fine (the empty space is still ready for filling), but as soon as the spaghetti plot is added, the whole chart is the spaghetti chart (the box field is erased).

Is there a way to make several different graphs on the same panel?

+4
source share
1 answer

As @DWin and @mnel note, you are having problems because you are trying to mix the graphics of the base graphics ( boxplot() ) and the grid ( xyplot() ). To get two drawers and a spaghetti patch in one shape, you have three main options. The first two will be much simpler than the third:

  • Use only the basic graphics (here boxplot() and plot( , type="b") ), placing them on the same shape using par(mfrow=c(1,3) .
  • Use only a graphics-based grid (here the lattice functions bwplot() and xyplot( , type="b") ), placing them on the same shape as grid.arrange() from gridExtra .
  • Use a mixture of base and grid -based graphics (for example, what you're trying to do now), combining them into one shape with the functions from the gridBase package.

The only thing that needs to be said for option 3 is that the persecution will teach you a lot about the low-level implementation of both basic and grid graphic systems!

+1
source

Source: https://habr.com/ru/post/1446861/


All Articles