编辑:添加指向正在使用的数据的链接(https://drive.google.com/open?id=0B0PKu0-SX1JPRW94SXFybFd6N2c)
在我开始之前,如果这是重复的话我会道歉但是经过数小时的研究后我似乎无法找到答案(虽然它可能存在......)。我想读取.csv文件中的数据并生成一个.png,显示指定工作目录中的密度和数据点。这应该能够从隔离的环境(例如USB驱动器)运行。
我的数据在.csv文件中。我已经制作了一些图像,但不像以下示例中所示(参见https://www.r-bloggers.com/reproducible-art-with-r/中的“图2A”):
原始示例
set.seed(16211)
rc <- rpoispp(function(x,y){50 * exp(-3*(max(y)-y))}, 100, win=W23)
rcdist <- distmap(rc, dimyx=c(1200, 800))
rc2 <- rpoispp(1/rcdist*50)
rcd <- dirichlet(rc2)
png(filename = "Figure_2A.png", width=6000, height=4000, res=400)
par(mai=c(0,0,0,0))
plot(rcdist, legend=FALSE, main="", frame=FALSE, box=FALSE, ribbon=FALSE)
plot(rcd, add=T)
plot(rc, add=T, col="black", pch=19, cex=2.5)
plot(rjitter(rc, 0.01), add=T, col="white", pch=19, cex=0.4)
contour(rcdist, add=T, col="white")
dev.off()
但我希望我的代码能够生成类似的图形但不使用随机点。当我坐在这里因睡眠不足而神志不清......我想出的最好的就是下面(我知道这可能是可怕的)。任何更正都会非常感激。
CURRENT ATTEMPT
# load workspace ----------------------------------------------------------
getwd()
setwd("D:/AH_DataToPng_Test/")
# install packages --------------------------------------------------------
install.packages("spatstat")
# load library ------------------------------------------------------------
library(spatstat)
# import my data ----------------------------------------------------------
my.data=read.csv("Figure.csv")
# view in table -----------------------------------------------------------
grid.table(my.data) #Visually confirms data input
# print the data using ppp ------------------------------------------------
# TODO: Answer - Is ppp(xdata, ydata, xrange, yrange) strictly for use in the "Plots" view window?
my.pattern <- ppp(my.data[,1],
my.data[,2],
c(-6,6),
c(-5.1,4.13))
# plot(my.pattern) #TODO: DOESN'T WORK... needed to plot the points?
# plot(density(my.pattern)) #TODO: DOESN'T WORK... needed to produce the neat color graph?
#TODO: Answer - How do I get both the points and density to display simultaneously?
# print the data to png ---------------------------------------------------
png(filename="AH_FinalProjectOutput.png",
units="in",
width=11,
height=8.5,
pointsize=12,
res=72)
# plot(my.data) DOESN"T WORK... NOT NEEDED FOR png()?
# pause for review --------------------------------------------------------
for(i in 1:9){
Sys.sleep(1)
}
dev.off()
答案 0 :(得分:0)
png(file="example%02d.png", width=200, height=200)
for (i in c(10:1, "G0!")){
plot.new()
text(.5, .5, i, cex = 6)
}
dev.off()
对我来说,这将在工作目录中创建11个png
个文件。我希望它有所帮助