combine 2 images in one image

Hello, I was wondering if someone know how I can combine 2 images into one image.
Here is code:

H <- c(32, 25, 14, 5)
par(mar=c(5,6,0.1,1)+.1)
barplot(H,
        xlab = "Frequency",
        ylab = "",
        names.arg = c("Earthy", "Buttery", "Starchy", "Chalky"),
        col = grey.colors(5),
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)


#Texture from First response
H <- c(101, 82, 79, 54, 42, 28, 21)
par(mar=c(5,6,0.1,1)+.1)
barplot(H,
        xlab = "Frequency",
        ylab = "",
        names.arg = c("Smooth", "Creamy", "Dry", "Thick", "Moist", "Grainy", "Soft"),
        col = grey.colors(7),
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)

Created on 2020-05-21 by the reprex package (v0.3.0)

Hello,

If you are willing to use the more powerful ggplot to create your graphs, the package you are looking for the is the gridExtra package.

Here is a nice vignette on how to get started: https://cran.r-project.org/web/packages/egg/vignettes/Ecosystem.html

If you prefer to just stick to the default R plots, read this one: https://www.statmethods.net/advgraphs/layout.html

Hope this helps,
PJ

1 Like

Thanks @pieterjanvc for your help and message. Can you please let me know why par() function is changing the plot format.
Here is code:

M <- c(32, 25, 14, 5)
par(mar=c(5,6,0.1,1)+.1)
barplot(M,
        xlab = "Frequency",
        ylab = "",
        names.arg = c("Earthy", "Buttery", "Starchy", "Chalky"),
        col = grey.colors(5),
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)


#Texture from First response
J <- c(101, 82, 79, 54, 42, 28, 21)
par(mar=c(5,6,0.1,1)+.1)
barplot(J,
        xlab = "Frequency",
        ylab = "",
        names.arg = c("Smooth", "Creamy", "Dry", "Thick", "Moist", "Grainy", "Soft"),
        col = grey.colors(7),
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)

par(mfrow=c(1,1))
barplot(M)

barplot(J)

Created on 2020-05-25 by the reprex package (v0.3.0)

Thanks for the link, I got it @pieterjanvc. How I can save this plot as tif file with 600 resolution.

M <- c(32, 25, 14, 5)
par(mar=c(5,6,0.1,1)+.1)
barplot(M,
        xlab = "Frequency",
        ylab = "",
        names.arg = c("Earthy", "Buttery", "Starchy", "Chalky"),
        col = grey.colors(5),
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)


#Texture from First response
J <- c(101, 82, 79, 54, 42, 28, 21)
par(mar=c(5,6,0.1,1)+.1)
barplot(J,
        xlab = "Frequency",
        ylab = "",
        names.arg = c("Smooth", "Creamy", "Dry", "Thick", "Moist", "Grainy", "Soft"),
        col = grey.colors(7),
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)

par(mfrow=c(1,2))
barplot(M, horiz = T, col = grey.colors(4), axes = T, axisnames = T, ylab = "",
        names.arg = c("Earthy", "Buttery", "Starchy", "Chalky"), xlab = "Frequency",
        fig=c(0.1,0.7,0.3,0.9))
barplot(J, horiz = T, col = grey.colors(7), axes = T, axisnames = T, ylab = "",
        names.arg = c("Smooth", "Creamy", "Dry", "Thick", "Moist", "Grainy", "Soft"),
        fig=c(0.1,0.7,0.3,0.9), xlab = "Frequency")

Created on 2020-05-25 by the reprex package (v0.3.0)

Hi again,

You can use the tiff() function to save a plot as tiff:

tiff("Plot.tiff", width = 12, height = 6, units = 'in', res = 300)
plot(mtcars[,c("drat", "wt")])
dev.off()

The tiff() function itself creates a blank canvas with the dimensions specified, then everything you plot before you call the dev.off() function will be written to that canvas. The def.off() is the part that actually saves the result to disk.

The jpeg(), png(), bmp() and pdf() are very similar functions if you like other image formats

Hope this helps,
PJ