我试图在我的情节后面放置一张图片。目前它并不位于我想要的0,0和120,200坐标之间。该情节是使用' sequence()'和线矢量。这就是它现在的样子: Image behind plot.
这是我的代码:
library(oro.dicom)
x1 = seq(0, 120, 2)
x3 = seq(2, 122, 2)
x4 = x3
y1 = rep(0, 61)
x2 = x1
y2 = c(runif(60) * 100)
a1 = x1
a3 = x3
b1 = rep(200, 61)
b2 = 200:130
dcmImages <<- readDICOM("/home/ishaan/Desktop/project/data/dcm/imx-000.dcm", verbose = TRUE,
recursive = FALSE, exclude = "sql")
image(t(dcmImages$img[[1]]), col = grey(0:64/64), axes = FALSE)
par(new = TRUE, usr = c(0, 122, 0, 208))
plot(NA, xlim = c(0, 122), ylim = c(0, 200), axes = FALSE)
segments(x1, y1, x2, y2)
segments(x3, y1, x3, y2)
segments(x2, y2, x3, y2)
# ==============================
y2 = c(runif(60) * 100)
yy1 = 200 - y1
yy2 = 200 - y2
segments(x1, yy1, x2, yy2)
segments(x3, yy1, x3, yy2)
segments(x2, yy2, x3, yy2)
谢谢!
答案 0 :(得分:0)
来自In R, how to plot with a png as background?
library(png)
#Replace the directory and file information with your info
ima <- readPNG("C:\\Documents and Settings\\Bill\\Data\\R\\Data\\Images\\FUpVB.png")
#Set up the plot area
plot(1:2, type='n', main="Plotting Over an Image", xlab="x", ylab="y")
#Get the plot information so the image will fill the plot box, and draw it
lim <- par()
rasterImage(ima, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4])
grid()
lines(c(1, 1.2, 1.4, 1.6, 1.8, 2.0), c(1, 1.3, 1.7, 1.6, 1.7, 1.0), type="b", lwd=5, col="white")