hermesh2
11/22/2015 - 12:19 AM

## 02 Solution1.R

``````# Solution 1
# S plot density ----------------------------------------------------------
p <-
ggplot(d, aes(x = CURRENT_FIX_X, y =CURRENT_FIX_Y)) +
annotation_custom(grob = image_1, # Image
xmin= 0, # Coordinates to represent the image
xmax= 1000,
ymin= 0,
ymax= 800
# The image has 700 pixel. But the matrix has the median in 400 and if a put the image with 700px the eyes are in 350 (coord y).
# The I changed the size to 800 px in order to adjust the eyes position to the data position
) +
coord_fixed(xlim = c(0, 800), ylim = c(0, 700))  + # fix the image in the coordinates that we deffined before
geom_point(data= d, aes(x = CURRENT_FIX_X, y =CURRENT_FIX_Y),  # coordinates
color="black", # Color point
# position=position_jitter(w=0.01,h=0.01), # Point plot desviation
alpha=0.5) + # Point transaparecen
stat_density2d(data= d, aes(x = CURRENT_FIX_X, y =CURRENT_FIX_Y , fill = ..level.., alpha = ..level..),
size= 100, bins= 50, geom='polygon') +
theme_bw() + # Kind of theme. I strongly recomend theme_bw
scale_fill_gradient( low = "green",   # Lowest color value
high = "red" # High color value
) +
scale_alpha_continuous(range=c(0.0, 1) , guide = FALSE) +
# You can play with the range to show a better image. Range belongs to [0, 1] interval
xlim(0, 1000) + # Control lim for x-axe
ylim(0, 700) # Control lim for y-axe
print(p)
jpeg(filename = "Results/Solution1.jpeg", width = 1000, height = 700, units = "px")
print(p)
dev.off()
# E plot density ----------------------------------------------------------``````