1

I am a newbie in R and try to adapt some ggplot graphs with the new version. I can't solve the depreciation syntax about a bar graph and a boxplot.

Thanks for your help

The first one :

   # colors
   cols = c("#7CAE00", "#00BFC4", "#F8766D", "#C77CFF")
   names(cols) = c("beer", "coffee", "soda", "wine")

  # boxplot
  ggplot(scores, aes(x=drink, y=score, group=drink)) +
  geom_boxplot(aes(fill=drink)) +
  scale_fill_manual(values=cols) +
  geom_jitter(colour="gray40",
  position=position_jitter(width=0.2), alpha=0.3) +
  opts(title = "Boxplot - Drink's Sentiment Scores")

And the second :

        ggplot(drink_neg, aes(y=mean_neg)) +
        geom_bar(data=drink_neg, aes(x=drinks, fill=drinks)) +
        scale_fill_manual(values=cols[order(drink_neg$mean_neg)]) +
        opts(title = "Average Very Negative Sentiment Score",
        legend.position = "none")
lrleon
  • 2,610
  • 3
  • 25
  • 38
trayvou jba
  • 145
  • 1
  • 7
  • Welcome to SO! Without any data, your example isn't [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), and it is difficult to help you. So please add some data, for example with `dput(head(scores, 20))`. – RHA Nov 07 '15 at 21:31
  • 2
    Kind of wondering what "depreciation syntax" is supposed to mean. – Mike Wise Nov 07 '15 at 21:55
  • 1
    For starters - `opts` is deprecated; use `theme` instead. Check out `theme` at [docs.ggplot2.org/current/](http://docs.ggplot2.org/current/) – Sandy Muspratt Nov 08 '15 at 00:07

1 Answers1

2

I like a challenge, so this is my best guess as to what you are after. I really only had to change the title to use labs instead of the depreciated opts.

# colors
cols = c("#7CAE00", "#00BFC4", "#F8766D", "#C77CFF")
names(cols) = c("beer", "coffee", "soda", "wine")

dks <- sample( names(cols), 100, replace=T )
scr <- sample( 1:10, 100, replace=T )
scores <- data.frame(drink=dks,score=scr )

# boxplot
ggplot(scores, aes(x=drink, y=score, group=drink)) +
  geom_boxplot(aes(fill=drink)) +
  scale_fill_manual(values=cols) +
  geom_jitter(colour="gray40",
              position=position_jitter(width=0.2), alpha=0.3) +
  labs(title = "Boxplot - Drink's Sentiment Scores")

Which yields this - is that what you are after?:

enter image description here

And for the second plot I think you want this, I only had to add the stat="identity" part:

library(dplyr)
drink_neg <- scores %>% filter( score<=4 ) %>% group_by(drink) 
                    %>% summarize(drinks=last(drink), mean_neg=mean(score) )


ggplot(drink_neg, aes(y=mean_neg)) +
  geom_bar(data=drink_neg, aes(x=drinks, fill=drinks),stat="identity") +
  scale_fill_manual(values=cols[order(drink_neg$mean_neg)]) +
  labs(title = "Average Very Negative Sentiment Score",
       legend.position = "none")

enter image description here

Mike Wise
  • 22,131
  • 8
  • 81
  • 104