-2

Suppose you have data points ranging from 10^9-10^13, that if you used ggplot, the scale on the graph would only show the order of 10^13 while anything less than that would be miniscule.

 ggplot(data=Category_type,
             aes(x=reorder(TYPE, dollars), y=dollars, fill=dollars )) +
  geom_bar(stat="identity") +
  coord_flip() +
  xlab("type") +
  ylab("dollars") +
  ggtitle("Highest Costs") +
  theme(legend.position="none") 

What would I have to change in this statement to accommodate for points that display the bars of order 10^9 ?

I stumbled upon this thread but it's not exactly what I'm looking for:

Transform only one axis to log10 scale with ggplot2

Nusc
  • 41
  • 9

1 Answers1

1

+ coord_trans(y = 'log10') will make a log transformed coordinate system.

Axeman
  • 32,068
  • 8
  • 81
  • 94
  • That works thanks! – Nusc Sep 07 '16 at 20:41
  • If I wanted to change the colour, where would that go in the above statement? – Nusc Sep 07 '16 at 20:41
  • 'the colour' can refer to almost any part of a plot. You'll have to specify. – Axeman Sep 07 '16 at 20:42
  • Suppose I want red bars for each category_type, they don't have to be distinct. – Nusc Sep 07 '16 at 21:43
  • Also, how does one add captions for these plots? – Nusc Sep 07 '16 at 21:46
  • That's all super basic stuff, just search yourself or look up a tutorial. – Axeman Sep 07 '16 at 21:49
  • Give me a reference. I have searched figure caption ggplot in R but nothing comes up for grid.arrange. I don't need to do it for the whole grid, even just for the ggplot. What is the syntax? With some references they're overcomplicated. I just want a simple caption below the plot. – Nusc Sep 08 '16 at 05:05
  • My search for 'figure caption ggplot in R' gives [this](https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html) page as the third hit, which shows how to do both grids _and_ captions (although it does rely on having another package). For the fanciest captions, see [here](http://docs.ggplot2.org/dev/labs.html), but you'll need the `dev` version of ggplot, which you can install from github using `devtools::install_github('hadley/ggplot2')`. I trust you fixed your red bars then? – Axeman Sep 08 '16 at 07:52
  • No where do I see a caption below the figure in the first link you provided. The second link does have one, ...+ labs(caption = "(based on data from ...)"), although it works, nothing shows when I use it. I could only find one statement that allows me to show highest bars as red and lowest as green but not all red. – Nusc Sep 08 '16 at 19:38
  • The first link shows how to write text _anywhere_ on the plot. For the second, you'll need to install the dev version as I said. – Axeman Sep 08 '16 at 19:44