Skip to content

levelplot blocks size

9 messages · Jonathan, Duncan Murdoch, Greg Snow

#
Hi,

I am trying to produce a levelplot using the following:

library(lattice)
df <- read.table("data", sep="\t", header=TRUE)

gr = levelplot(df$z ~ df$x * df$y,
xlim=0:1000,ylim=0:1000,aspect="iso",col.regions=heat.colors)
print(gr)

The produced result is: http://dl.dropbox.com/u/25473/bigplot.png

Now this is correct, because each of those points have a very low z value,
but what I'm more interested in is grouping these values together and
plotting a larger point for all of those smaller points.

For example, when I limit the x and y axes further, I get the following
(where x and y axes are limit to 0:10):

http://dl.dropbox.com/u/25473/smallplot.png

Now this is good, but this data gets totally lost when plotted like in the
first example, so I need to create larger "blocks", then compute a z value
for that entire block.

The question is: how do I do this?

Any help much appreciated!

Thanks,

Jonathan
3 days later
#
Sorry to bump this up again, but I've been continuing to look for a solution
to this including a look into stats.bin but I still can't find any solution
to do this within R.

Any help would be much appreciated!

Thanks,

Jonathan
#
On 19/12/2010 2:10 PM, jonathan wrote:
See ?levelplot.  The number of bins of x and y is equal to the number of 
unique x and y values.  If you want fewer, just round the values instead 
of using 1:1000.

Duncan Murdoch
#
Duncan,

Thanks for the help.

I'm new to R, so I'm not sure how to get R to round the values and "group"
them into larger blocks.

I have tried the following:

xlim=seq(0,2000,100),ylim=seq(0,2000,100)

just to see if it would work, but it doesn't...

Do you think you might be able to explain how to go about rounding the
values?

Thanks,

Jonathan
#
On 19/12/2010 2:46 PM, jonathan wrote:
I don't know what your data looks like, so this is hard.  levelplot 
assumes you have triplets (x,y,z), where x and y only take a few values, 
and it plots the grid of those values using z to set the colour.  In 
your example you read x amd y from a file.  So just round them to fewer 
values, e.g.

df$x <- round(df$x, -2)  # round to -2 decimal places, i.e. to hundreds
df$y <- round(df$y, -2)

levelplot(z ~ x+y, data=df)
7 days later
#
Thanks for your advice, but my data is not decimals, so I don't need to round
the values. Instead, what I need to really do is "group" the values into
larger "blocks".

My data looks sort of like this:

x    y     z 
0    0    687 
0    1    64 
0    2    71 
0    3    55 
0    4    52 
0    5    51 
0    6    38 
0    7    38 
0    8    54 
0    9    49 
......... 
......... 
......... 
987   988    1
999   998    1
999   999    1


But what I need to do is make it so that on the graph rather than having
tiny little dots for each point (as shown in the bigplot diagram), there are
bigger points, so say 0<=x<10, 0<=y<10 is one point in the lower left,
rather than having 100 points for each x,y value.

The same strategy should then be applied to the whole graph.

Any ideas how to achieve this? I'm sure this is quite a common thing to do
want to with heatmaps??

Thanks,

Jonathan
#
Look at the functions cut, findInterval, tapply, and aggregate. 

Sent from my iPod
On Dec 26, 2010, at 4:34 PM, "jonathan" <jon at than.biz> wrote:

            
#
Thanks for your help.

Might you be able to explain in a little more detail how to use those
functions to solve this specific problem?

I'm happy to put in the work myself and have looked up those functions but
am new to R and still a little unsure about how I would go about using those
functions to solve my problem.

Thanks,

Jonathan
#
Here is a basic example: 

tmp.df <- expand.grid( x= 1:100, y=1:100 )
tmp.df$z <- with(tmp.df, x+2*y)

library(lattice)
levelplot( z ~ x + y, data=tmp.df )

tx2 <- with(tmp.df, cut(x, seq(0.5, 100.5, 10) ) )
ty2 <- with(tmp.df, cut(y, seq(0.5, 100.5, 20) ) )

tmp.df2 <- aggregate(tmp.df, list( tx2, ty2 ), mean )

levelplot( z ~ x + y, data=tmp.df2 )


Hope this helps,