1

I have a dataframe in R:

Dept 1.    Dept 2.   Dept 3.    Dept 4.    Dept 5. 
    0.5       0.1      -0.3         0.4      -0.1

With each number representing how much the revenue increased or decreased in each department.

I want to graph this data as set of circles such that:

  • The change for each department is represented by an individual circle.

  • The size of the circle is proportional to the magnitude of the change in the department's revenue.

  • The circle is green if the corresponding revenu change is positive.

  • The circle is red if the corresponding revenu change is negative.

I'm thinking it might be possible to do this using ggplot in R.

Is it? And how would I go about doing it?

Alex Kinman
  • 2,437
  • 8
  • 32
  • 51
  • 2
    This sounds like a duplicate. Have you done any searching? – IRTFM Mar 30 '18 at 22:51
  • @42- yes I did. If it's a duplicate, can you point to it please. – Alex Kinman Mar 30 '18 at 23:00
  • Here's how I often SO search when I think it's likely to be a dupe. I take the title of the question an keep removing what I think might be extraneous. I get: https://stackoverflow.com/questions/22011980/map-with-geom-bin2d-overlay-with-additional-stat-info using: "[r] ggplot2 size circles proportional ". To me it looks pretty much a duplicate. Of course one should also google-search as well as SO-search before posting. – IRTFM Mar 30 '18 at 23:16

1 Answers1

1

Try this:

library(reshape2)

df <- data.frame(d1=1, d2=-1, d3=10, d4=3)

df <- melt(df)
df$pos <- sign(df$value) == 1
df$scale <- abs(df$value) *10

ggplot(data=df, aes(x=variable, y=1, colour=pos, size=scale))+
  geom_point()+
  scale_colour_manual(values= c("forest green", "red3"))+
  xlab("Dept")+
  theme_minimal()+
  scale_size_continuous(range=c(4,20))

You may want to either pick something to map to the y axis or remove the gridlines and labels from the y.

Luke Hayden
  • 692
  • 4
  • 8