2
$\begingroup$

UPDATED: added larger dataset to give more detail. Example below is for one office location.

I want to create a simple visualisation to show how far a set of supplier locations are from certain offices. So the data would look something like:

company_name   office_location   distance   
'ABC Corp'     'London'          39
'ZX Spec Ltd'  'London'          3.5
'Global Biz'   'London'          106
'UKTC LLC'     'London'          2.3
'Venture Ltd.' 'London'          23
'Ace LLC'      'London'          1
'RedBiz Ltd.'  'London'          3
'Blueco Ltd.'  'London'          2.2
'Greencom'     'London'          43
'Noname Ltd.'  'London'          40
'Anonon LLC'   'London'          39 
'ABC Corp'     'Birmingham'      9
'ZX Spec Ltd.' 'Birmingham'      22
…

About 100 rows in total for seven office locations. Ideally I would have separate visualisations for each of these office location 'groups' (one each for London, Manchester etc.) At first I was going to put them on a map, but it seems like overkill. Ideally I would have a very simple line for each office location with labelled marks for each of the companies: rather like the London Tube or NYC Subway maps, except with the distances between the points scaled. The people receiving this won't be able to click, so anything interactive will be wasted on them. Direction isn't important, just distance, which is why I thought this sort of straight line viz might work well.

I am sure there must be a way to do this but I just cannot figure it out (save for manually creating them as drawings, but there must be a better way!)

Can you suggest anything? I have access to Excel, Tableau and R (among others).

$\endgroup$
8
  • $\begingroup$ Suggestions for how to visualize these data is an interesting question. Be aware that asking for code is off topic here. $\endgroup$ Jul 15, 2016 at 21:58
  • $\begingroup$ OK cool, this is my first question on Stack Exchange so any input on best place to post would be useful: if I needed code is it something that should go on Stack Overflow? $\endgroup$
    – hamedbh
    Jul 15, 2016 at 22:05
  • $\begingroup$ I think you're fine to stay here, unless you only want code. But you might find that the code isn't difficult once you've figured out what you want. $\endgroup$ Jul 15, 2016 at 22:07
  • $\begingroup$ Do the distances between the suppliers matter? Is there any natural ordering of the suppliers? $\endgroup$ Jul 15, 2016 at 22:08
  • $\begingroup$ The only ordering of the suppliers is by their distance within each office location group. I suggested just a table, perhaps even done with colour (Tableau has an option to do this easily), but they want something "more visual". They suggested a map, but I thought that was less clear than a table or the sort of simple 'marks on a line' idea I suggested above. $\endgroup$
    – hamedbh
    Jul 16, 2016 at 5:23

2 Answers 2

4
$\begingroup$

Possible use of geom_label_repel():

library(ggplot2)
library(dplyr)

read.table(text="company_name   office_location   distance   
'ABC Corp'     'London'          39
'ZX Spec Ltd'  'London'          3.5
'Global Biz'   'London'          106
'UKTC LLC'     'London'          2.3
'Venture Ltd.' 'London'          23
'Ace LLC'      'London'          1
'RedBiz Ltd.'  'London'          3
'Blueco Ltd.'  'London'          2.2
'Greencom'     'London'          43
'Noname Ltd.'  'London'          40
'Anonon LLC'   'London'          39 
'ABC Corp'     'Birmingham'      9
'ZX Spec Ltd.' 'Birmingham'      22", 
           stringsAsFactors=FALSE, header=TRUE) -> places

group_by(places, office_location) %>% 
  summarise(max=max(distance)) -> max_l


gg <- ggplot()
gg <- gg + geom_segment(aes(x=1, xend=max, y=office_location, 
                            yend=office_location), max_l)
gg <- gg + geom_label_repel(aes(x=distance, y=office_location, label=company_name), 
                            places, fill="white", size=3)
gg <- gg + scale_x_continuous(expand=c(0,0), 
                              labels=c("0 (km)", seq(25, 100, 25)), 
                              limits=c(0, 110))
gg <- gg + labs(x=NULL, y=NULL)
gg <- gg + theme_minimal()
gg

enter image description here

$\endgroup$
2
  • $\begingroup$ This looks very close to what I had in mind. Would I be able to arrange the labels so that they were all in the same position (i.e. above the line, at 45˚ angle to the line)? $\endgroup$
    – hamedbh
    Jul 16, 2016 at 15:48
  • $\begingroup$ take a look at the nudge_x and nudge_y parameters (you can give each node a separate value column for each of those and put them in the aes()). That may help a bit, but I'd personally try to get it to be as close as you can then export to SVG or PDF and use something like Omnigraffle or Inkscape to finish it manually. $\endgroup$
    – hrbrmstr
    Jul 16, 2016 at 16:01
3
$\begingroup$

I would use a dotplot for this. I would first sort by distance (unless something else made more sense in the business context), and group the values by the office in question.

enter image description here

The issue with scaling this up to 100 data, is that the company names become very small. I alternately added some whitespace to the names to stagger them to keep them from overlapping. I also shrunk the font, shrunk the outer margin, and made the plot bigger. In my opinion, this will be imperfect unless you can present a big plot, or break the dataset up onto more than one plot.

enter image description here

$\endgroup$
1
  • $\begingroup$ I think breaking it up into separate plots will be the way to go. $\endgroup$
    – hamedbh
    Jul 16, 2016 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.