I have a data set like this (simplified for illustration purposes):
zz <- textConnection("Company Market.Cap Institutions.Own Price.Earnings Industry
ExxonMobil 405.69 50% 9.3 Energy
Citigroup 156.23 67% 18.45 Banking
Pfizer 212.51 73% 20.91 Pharma
JPMorgan 193.1 75% 9.12 Banking
")
Companies <- read.table(zz, header= TRUE)
close(zz)
I would like to create a bubble chart (well, something like a bubble chart) with the following properties:
To be clear, each company will appear in each column of the result, for example ExxonMobil will be near the bottom of both the Institutions.Own column and the Price.Earnings column; ideally, the name of the company would appear in or next to both of its bubbles.
I think this touches on all of your points. Note - your Institutions.Own
is read in as a factor because of the %
...I simply deleted that for ease of time...you'll need to address that somewhere. Once that is done, I would use ggplot
and map your different aesthetics accordingly. You can fiddle with the axes titles et al if you need.
#Requisite packages
library(ggplot2)
library(reshape2)
#Define function, adjust this as necessary
rescaler <- function(x) 10 * (x-min(x)) / (max(x)-min(x))
#Rescale your two variables
Companies$Inst.Scales <- with(Companies, rescaler(Institutions.Own))
Companies$Price.Scales <- with(Companies, rescaler(Price.Earnings))
#Melt into long format
Companies.m <- melt(Companies, measure.vars = c("Inst.Scales", "Price.Scales"))
#Plotting code
ggplot(Companies.m, aes(x = variable, y = value, label = Company)) +
geom_point(aes(size = Market.Cap, colour = Industry)) +
geom_text(hjust = 1, size = 3) +
scale_size(range = c(4,8)) +
theme_bw()
Results in: