Creating a hexplot

326 views Asked by At

I am trying to create a figure like the one depicted in the third column of the following image:

enter image description here

Link for the image in case of backup.

Basically I have x and y positions of 200 particles and I have the MSD data for these 200 positions. I'd like MSD to be the value that should determine a color map for the particles in coordinates (x,y). So MSD should be like the height, or the z position corresponding to each particle in (x,y).

I am surprised at my incompetence, because I have been trying to solve this problem for the last couple of days but none of the Google searches gave me any result. The closest thing that I have found is the concept of "self-organizing map" in Matlab and R, but I do not know how to use R and Matlab's toolbox for SOM was utterly useful for my needs.

I tried the following code in Matlab and get the attached plot as a result:

clear all; close all; clc;

x = (dlmread('xdata.dat'))'; % x is 1x200 array
y = (dlmread('ydata.dat'))'; % y is 1x200 array 
msd = (dlmread('msd_field.txt'))'; % msd is 1x200 array

[X,Y] = meshgrid(x,y);
Z = meshgrid(msd);
z = [X; Y; Z]; 
surf(z)

But I think this plot is not useful at all. What I want is a 2D scatter plot of (x,y) depicting particle positions and on top of that color code this scatter plot with the values stored in msd like the plot I showed in the beginning. How can I create this through Matlab, or any other visualization tool? Thank you in advance.

Surface graph

1

There are 1 answers

2
agstudy On BEST ANSWER

It is not clear whay you want to have. Here a scatter plot using ggplot2.

## some reproducible data 
set.seed(1)
dat <- data.frame(
  x = round(runif(200,-30,30),2),
  y = round(runif(200,-2,30),2),
  msd = sample(c(0,2,3),200,rep=T))

## scatter plot where the size/color of points depends in msd
library(ggplot2) 
ggplot(dat) +
  geom_point(aes(x,y,size=msd,color=msd)) +
  theme_bw()

enter image description here