0

I am plotting a simple geom_point with year as the x axis and a percentage rate as the y axis. For some reason the y axis is not placing the rate from smallest to largest and instead has the two smallest rates at the top with the rest being in order smallest to largest bottom to top, respectively. Here is my code:

df1= ggplot(ball, aes(year,krate))
df1 + geom_point()
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1
    Welcome to SO, Benjamin Moxley! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically after `set.seed(1)`), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jan 27 '21 at 19:09
  • Having said that, just about every question on SO that includes [tag:ggplot2] and mentions "order" and "axis labels" is resolved by the use of `factor` and/or assigning the `levels`. See for yourself: [`[r] [ggplot2] axis labels order`](https://stackoverflow.com/search?q=%5Br%5D+%5Bggplot2%5D+axis+labels+order). – r2evans Jan 27 '21 at 19:10
  • My guess is that `krate` is `character` and not `numeric` or `integer`. I suggest that you don't try to add `%` signs or stringify the percentage before the plot, instead handling it with a [`labeller`](https://ggplot2.tidyverse.org/reference/labeller.html) or with `scale_y_continuous(labels = scales::percent)`. – r2evans Jan 27 '21 at 19:30
  • 1
    That was it, my source data had the percent signs already, once I changes the format it plotted correctly, thanks! – Benjamin Moxley Jan 27 '21 at 20:41

0 Answers0