0

I have this data set

data of Staff strength and total Applications received

df <- data.frame(year = seq(1970, 2015, by = 5),
                 staff = c(219, 231, 259, 352, 448, 427, 556, 555, 602, 622),
                 applications = c(5820, 7107, 6135, 16119, 19381, 36611, 54962, 45759, 40358, 458582))

I want to perform the exploratory analysis and want to compare whether the staff strength is growing according to the applications received. I plotted a line graph using excel : enter image description here

which isn't very meaningful. I've also taken the log of both variables which almost got the desired result but i wonder if the graphs with log are less explainable to non-mathematicians. Since i want to use these kind of graphs in a presentation to my managerial staff who don't know much of statistics or mathematics. My question is how to tackle this situation in order to draw a meaningful graph. I've a gut feeling that R might have a better solution(that is why i asked here ) than Excel but the problem is 'How'?

Any help will be highly appreciated.

3
  • In ggplot2, you can use faceting with free_y.
    – Gopala
    Commented Apr 6, 2016 at 17:39
  • Are you sure the last number in total application isn't a mistake or typo? In your plot, you can put an alternate y-axis for "santioned" so that it is not compressed. You can compute the correlation.
    – fishtank
    Commented Apr 6, 2016 at 17:53
  • @fishtank .. It is not a mistake because online application system adopted in 2011 resulted in greater number of applications dramatically . Commented Apr 7, 2016 at 16:22

3 Answers 3

3

One recommendation would be to change your measure into some type of ratio metric. For example, staff per applications. In the following, I will use staff per 1,000 applications:

library(ggplot2)

df <- data.frame(year = seq(1970, 2015, by = 5),
                 staff = c(219, 231, 259, 352, 448, 427, 556, 555, 602, 622),
                 applications = c(5820, 7107, 6135, 16119, 19381, 36611, 54962, 45759, 40358, 458582))

ggplot(data = df, aes(x = year, y = staff / (applications / 1000))) +
  geom_point(size = 3) +
  geom_line() +
  ggtitle("Staff per 1,000 Applications")

Plot 01

We can achieve the same result without ggplot2 with:

with(df, 
      plot(x = year, y = staff / (applications / 1000), type = "l", main = "Staff per 1,000 Applications") + 
        points(x = year, y = staff / (applications / 1000), pch = 21, cex = 2, bg = "black")
     )

Base R Plot


Alternatively, you could make your dataset a little more tidy (see this, this, and/or this for more information) and plot them two facets with free_y scales:

library(tidyr)

df_tidy <- gather(df, measure, value, -year)

ggplot(data = df_tidy, aes(x = year, y = value)) +
  geom_point(size = 3) +
  geom_line() +
  facet_grid(measure ~ ., scales = "free_y")

Plot 02

0
1

I would suggest you to use facet_grid with scales = "free_y".

ggplot(reshape2::melt(df, 1), aes(year, value)) + 
    geom_line() + geom_point() + 
    facet_grid(variable ~ ., scales = 'free_y')

The output you will get is, Output

0

enter image description here

    we can use this process:



                  library(ggplot2)
                  library(reshape2)
                  ggplot(df, aes(year)) + 
                  geom_line(aes(y = staff, colour = "staff")) + 
                 geom_line(aes(y = applications, colour = "applications"))




             df <- data.frame(year = seq(1970, 2015, by = 5),
             staff = c(219, 231, 259, 352, 448, 427, 556, 555, 602, 622),
             applications = c(5820, 7107, 6135, 16119, 19381, 36611, 54962, 45759, 40358, 458582)

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.