简体   繁体   中英

R: how to plot data from two separate data.frames

dat.x <- data.frame(var1 = 1, var2 = 1.5, var3 = 3)
dat.y <- data.frame(var1 = 3, var2 = 1.5, var3 = 3)

plot(dat.x$var1, dat.y$var1, col = "red", xlim = c(0.6, 3.5), ylim = c(0, 4), xlab = "x", ylab = 'y')
points(dat.x$var2, dat.y$var2, col = "blue")
points(dat.x$var3, dat.y$var3, col = "green")

在此处输入图像描述

I have two data.frames, dat.x and dat.y , that contain the x and y coordinates of 3 observations. Is there a quick way to plot these points? Perhaps using melt from the reshape2 package to organize the 2 data.frames into a single one?

dat.x <- data.frame(var1 = 1, var2 = 1.5, var3 = 3)
dat.y <- data.frame(var1 = 3, var2 = 1.5, var3 = 3)

dat.z <- matrix(data = c(dat.x, dat.y), nrow = 3, ncol = 2)
dat.z <- as.data.frame(dat.z, row.names = c("var1", "var2", "var3"))

plot(dat.z)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM