Visualizing complex data in geographical space using PCA colouring

I have recently had some very interesting dicussions with scientists in China about visualizing complex AMR data (e.g. patterns of gene abundance or bacterial taxa) in geographical space to show if data from nearby locations are similar or different from each other. Our collaborators had already shown that PCA was successful at separating the data, so the idea I had was to use the PCA scores to colour points which could then be plotted on a map at the locations from which the data were derived. Nearby points with similar data should then have similar colours, while nearby points with different data should have different colours.

To test the idea, I used a built in data set in R (state.x77 in the datasets package). This has demographic data about states in the USA, as well as longitude/latitude coordinates for the centres of the states. In the analysis I have:

1. Run a PCA on the demographic data
2. Normalized the first three PCA scores to be between 0 and 1 (since this is what the rgb() function in R requires to define colours)
3. Used a simple map library to plot a map of the USA including state boundaries
4. Plotted the points into the centres of the states using the rgb() defined colours

What you can see in the map (below) is that generally nearby states are similar to each other in that they have similar colours – but there are some exceptions where the colours are very different.

statemap

The code is:

require(maps) # Simple R interface for maps
require(datasets) # Contains some example data

# This function converts a range into the range [0,1) which we need for the rgb colour map
normalize = function(x,eps=1e-3) { # eps is a small number to ensure the outputs are all <1 as rgb doesn't like values of 1
    xnorm = as.numeric((x-min(x))/(max(x)-min(x)+eps))
    return(xnorm)
}

spc = princomp(state.x77[,3:6]) # this is some demographic data about states in the USA - it is just an example
sred = normalize(spc[[6]][,1])
sgreen = normalize(spc[[6]][,3]) # this order, i.e. using blue on the 2nd PC, is to help red-green colour blind people
sblue = normalize(spc[[6]][,2])

map('usa') # draws a simple map of USA
map('state',add=T) # adds state boundaries
points(state.center$x,state.center$y,pch=19,col=rgb(red=sred,green=sgreen,blue=sblue)) # puts coloured points into the centre of each state. An alternative could be to fill the states
Advertisements

New publication:So why have you added me? Adolescent girls’ technology-mediated attachments and relationships.

Work from Di’s PhD has just been published! This is very much Di’s work. My contribution was making the figures in R. Very proud of Di! This is my first social research article – my publication record becomes increasingly eclectic.

Levine DT and Stekel DJ 2016. So why have you added me? Adolescent girls’ technology-mediated attachments and relationships. Computers in Human Behaviour 63:25-34.

Highlights

  • Adolescent girls can develop attachment with others through, and with, technology.
  • Adolescent girls use technology to meet others and mediate relationships.
  • Facets of relationships can be understood as functions of secure relationships.
  • Functions include proximity-seeking, trust, exploration and return to secure base.
  • Technology use can amplify girls’ secure relationships with peers and parents.

Abstract

Technology plays an almost ubiquitous role in contemporary British society. Despite this, we do not have a well-theorised understanding of the ways adolescent girls use digital devices in the context of their developing secure relationships with their families and friends. This study aims to address this gap in understanding. Fifteen young women based in the Midlands and from across the socio-economic spectrum participated between 2012 and 2013. Participants completed three research tools exploring technology-mediated attachment and relationships, and participated in a face-to-face interview. The findings suggest that it is possible for girls to develop attachments with others through, and with, technology; technology use brings people together and mediates relationships in a range of ways encapsulated by attachment functions. The study highlights the ongoing importance of parental and peer relationships by suggesting that technology can act as a means by which the positive and negative attributes of existing relationships can be amplified.