0

I recently discovered the geofacet package in R. Amazing. I have 5 years worth of data for each state. I have horizontal bars in each facet. I am trying to figure out how to add a simple label that shows the value of each bar in each graph such that it sits off to the right of the bar or right side of the facet. I have tried geom_text and a number of code lines but nothing seems to add the labels for each bar in each facet.

Below is my code to make the geofacet of the US. Not sure where to add the label code either.
Any help is greatly appreciated. This is my last step to complete this awesome map.

ggplot(Alabamatest, aes(YEAR, SALES, fill = YEAR)) +
  geom_bar(alpha=1, width = .75,
    aes(color =TYPE, fill=TYPE),
    stat = "identity", position = position_stack(reverse = TRUE)
  ) +
  scale_color_manual(values = c("firebrick1", "cornflowerblue"))+
  scale_fill_manual(values = c("firebrick1", "cornflowerblue"))+
  ylim(0,9
  )+
  coord_flip() +
  theme_bw()+
  facet_geo(~ state, grid= "us_state_grid4", label ="SALES")+
  scale_y_continuous(expand = c(0, 0)) +
  labs(title = "2019 State Average Sales",
       caption = "Data Source: Year End Data",
       x = NULL,
       y = "Percentage of Voters") +
  theme(axis.title.x = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        strip.text.x = element_text(size = 6))

I am adding some test data to run with the code. I am not sure how to add a simple data frame so I have typed it out here. I am brand new to Stackoverflow. Apologies if this is not the correct way to present data

state    name    YEAR    SALES    TYPE
AL     ALABAMA    2019     2       POS
AL     ALABAMA    2018     1.5     POS
AL     ALABAMA    2017     1.4     NEG
AL     ALABAMA    2016     1.7     NEG
AZ     ARIZONA    2019     3       POS
AZ     ARIZONA    2018     3       POS 
AZ     ARIZONA    2017     2       POS
AZ     ARIZONA    2016     3.4     POS
AZ     ARIZONA    2015     5       POS

The two states create bar graphs. I want to be able to add the sales label to the right side of the bar graph for each year.

camille
  • 16,432
  • 18
  • 38
  • 60
  • Without any of your data, we can't run your code, and since you haven't included any output it's unclear what you're looking at and what you want to change. – camille Feb 27 '20 at 14:52
  • Hi. I added the data the best way I knew how. The code should run with the two states of data and you will be able to see the graphs in the geofacets and then I would like to figure out how to add the sales labels on the right side of the graph in each state geofacet. – Matthew Abnet Feb 27 '20 at 17:27
  • well now I see the data isnt in a form that can be used. I dont know how to add the data to this post. – Matthew Abnet Feb 27 '20 at 17:29
  • The guidance on making reproducible R examples is [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – camille Feb 27 '20 at 17:43

0 Answers0