0

I am trying to create a geom_ribbon chart, but the plot only shows the axes, without the plots.

The codes I wrote:

install.packages("tidyverse")
library("tidyverse")
data("diamonds")

ggplot() +
  geom_ribbon(data=diamonds,
    mapping = aes(
      y=carat,x=cut,
    ymin = min(carat),
    ymax = max(carat)
    ), fill = "blue"
  )

The result I got: enter image description here I would like to know where went wrong. Thanks.

I tried to get help from https://mpn.metworx.com/packages/ggplot2/3.3.0/reference/geom_ribbon.html but could not relate the examples to my own problem.

Kiki Liu
  • 27
  • 3
  • this works: `ggplot() + geom_ribbon(data=diamonds, mapping = aes( x=carat, ymin = price - 1000, ymax = price + 1000), fill = "blue" )` – Mark Aug 07 '23 at 09:49
  • update: I think it's because ordinal data can't be conclusively turned into numbers - "Ordinal data is a categorical, statistical data type where the variables have natural, ordered categories and the distances between the categories are not known" – Mark Aug 07 '23 at 09:51
  • i.e. we know that Ideal is better than Very Good, but Very Good could be a 6 out of 10, a 7, or something completely different! – Mark Aug 07 '23 at 09:53
  • hope this is helpful Kiki! :-) – Mark Aug 07 '23 at 09:54
  • May I ask: 1. what does "price-1000" and "price+1000" mean? – Kiki Liu Aug 07 '23 at 10:33
  • 2. is there a way to plot: in each cut category, the band width between the lowest carat and the highest carat? – Kiki Liu Aug 07 '23 at 10:35
  • yeah sure! 1. So, from what I understand, geom_ribbon is used often for something like a range- an example could be the finishing times in the 100 metres at the Olympics, with the range being the fastest to the slowest times. Because I'm not familiar with the dataset, but also because I don't think this dataset has that kind of data, instead of plotting a high and low over time, I'm using the value plus and minus 1000 – Mark Aug 07 '23 at 10:37
  • 2. if you really want to do it regardless - ```diamonds |> mutate(cut = as.numeric(cut)) |> summarise(min = min(price), max = max(price), .by = cut) |> ggplot() + geom_ribbon(mapping = aes(x=cut, ymin=min, ymax=max), fill="blue")``` - though you can see from this if you just look at the dataframe before it is fed into ggplot that the range is so broad and the numbers vary so little that it's like a big blue bar – Mark Aug 07 '23 at 10:43

0 Answers0