Plotting in R 3.1.2

71 views Asked by At

I have records of data by account (say unique 400 records). Each record has three different indications indicated premium. For each record, I am concerned with how the indications compare to each other. In some cases, the indications may be all relatively in line, while in other the 3 indications will be volatile and very different. These records also have a state associated with them.

Anyways, I am wondering if there is a nice way to visualize the by record differences between the 3 indications. Also, whether or not there is a nice way to visualize the indication differences by state (perhaps on a map-like view in R??).

I have plotted the distributions of each individual indication using density plots which has been helpful, but here I am asking about a visualization of the differences between 1, 2, or all 3 indications for each record. Is what I am asking possible?

Thank you so much.

1

There are 1 answers

1
JasonAizkalns On BEST ANSWER

Perhaps something like this is what you're after, but this would be easier if you would provide sample data and be more descriptive in the exact question you are asking:

library(ggplot2)
library(dplyr)
library(tidyr)

df <- data.frame(id = 1:400,
                 state = state.abb, 
                 ind1 = rnorm(400),
                 ind2 = rnorm(400),
                 ind3 = rnorm(400))

df %>%
  mutate(diff_1_2 = ind1 - ind2,
         diff_1_3 = ind1 - ind3,
         diff_2_3 = ind2 - ind3) %>%
  gather(metric, value, -c(id, state)) %>%
  filter(metric %in% c("diff_1_2", "diff_1_3", "diff_2_3")) %>%
  ggplot(., aes(x = metric, y = value)) +
  geom_boxplot() +
  facet_wrap(~ state)