Reputation: 31
I have a data.frame as this:
> head(shht)
tt2 imf f a
1 1 c1 0.025735102 461.1430
2 2 c1 0.025735102 336.5967
3 3 c1 0.012977971 334.0539
4 4 c1 0.013013110 303.7454
5 5 c1 0.009130993 301.7031
6 6 c1 0.009153142 287.5305
the data is here
There are a total of four columns. I want to draw a pixmap. The first column is the horizontal axis, the third column is the vertical axis, and the fourth column is the grayscale value.
I tried the following:
> simage=as.image(shht$a,x=cbind(shht$tt2,shht$f))
> image.plot.ts(simage,tt=tt2)
Error in plot.new() : figure margins too large
the image.plot.ts() is a function from EMD. and the as.image() comes from fields.
Upvotes: 0
Views: 1194
Reputation: 6020
You could use the image
function by generating a matrix of your data?
x = rep(1:5,5)
y = rep(1:5, each = 5)
d = sample(1:10, length(x),replace = T)
df <- data.frame(x = x, y = y, d = d)
mat <- matrix(df[order(df$x, df$y),'d'], 5)
image(mat)
Or you could make a simple plot of your data, mimicking pixels.
plot(x, y, col=d, pch=15, cex=4)
edit: I dont fully understand how your data needs to become an image. Since you have only one datapoint per x co-ordinate:
id <- "0B3bNSNFik5wGNGY4VEQ0TFltM3M"
dat <- read.csv(sprintf("https://docs.google.com/uc?id=%s&export=download", id))
ggplot(dat, aes(x = tt2, y = f, color=a)) + geom_point() + theme_bw()
produces
Upvotes: 1
Reputation: 2469
This is a package for direct manipulation of bitmap images. pixmap It has a range of methods for creating and manipulating them.
One example, directly from the reference manual:
library(pixmap)
x <- seq(-3,3,length=100)
z1 <- outer(x,x,function(x,y) abs(sin(x)*sin(y)))
z2 <- outer(x,x,function(x,y) abs(sin(2*x)*sin(y)))
z3 <- outer(x,x,function(x,y) abs(sin(x)*sin(2*y)))
z <- pixmapRGB(c(z1,z2,z3), 100, 100, bbox=c(-1,-1,1,1))
plot(z, axes=TRUE)
Upvotes: 0