0

I need help for two things;

  • First one; Need to set axis (x and y) in the point (1;1). like in this picture:

enter image description here

  • Second; limit the scale to 0.1 (in the graphic i would see in the axe x [ 0.8 1 1.2 1.4 1.6] same in y-axe, but not [0.73 0.77 0.81 0.93 ...etc]

Here's my data:

structure(list(Finess = c(20000063L, 20000063L, 20000063L, 590781415L, 
590781415L, 590781415L, 590781902L, 590781902L, 590781902L, 590782215L, 
590782215L, 590782215L, 590782421L, 590782421L, 590782421L), 
    Etablissement = structure(c(3L, 3L, 3L, 4L, 4L, 4L, 2L, 2L, 
    2L, 1L, 1L, 1L, 5L, 5L, 5L), .Label = c("CES", "CG", "CN", 
    "CUE", "CX"), class = "factor"), DA_ASO = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "D01-C", class = "factor"), 
    Annee = c(2018L, 2019L, 2020L, 2018L, 2019L, 2020L, 2018L, 
    2019L, 2020L, 2018L, 2019L, 2020L, 2018L, 2019L, 2020L), 
    IPDMS = structure(c(10L, 13L, 11L, 6L, 3L, 7L, 5L, 9L, 8L, 
    2L, 1L, 4L, 14L, 12L, 15L), .Label = c("0.783", "0.808", 
    "0.824", "0.825", "0.884", "0.901", "0.913", "0.976", "0.977", 
    "1.006", "1.030", "1.039", "1.073", "1.094", "1.107"), class = "factor"), 
    Indice_Sever = structure(c(1L, 3L, 5L, 6L, 13L, 7L, 9L, 10L, 
    11L, 14L, 15L, 12L, 8L, 4L, 2L), .Label = c("0.863", "0.898", 
    "0.901", "0.948", "0.962", "1.009", "1.011", "1.038", "1.052", 
    "1.075", "1.085", "1.130", "1.151", "1.153", "1.205"), class = "factor"), 
    label = structure(c(4L, 1L, 1L, 5L, 1L, 1L, 3L, 1L, 1L, 2L, 
    1L, 1L, 6L, 1L, 1L), .Label = c("", "CES", "CG", "CN", "CUE", 
    "CX"), class = "factor")), class = "data.frame", row.names = c(NA, 
-15L))

Here's the code that i use:

    ggplot(df, aes(x = IPDMS, y = Indice_Sever,xlim=c(0.5), ylim=c(0.5), label = label, group = 
    Finess)) + 
      geom_path(arrow = arrow()) + 
      geom_text(nudge_x = .2, nudge_y = 0) +
      labs(
        title = paste("XXXXXXX", params$da_aso),
        subtitle = "Période 2018-2020, ets. publics",
        x = "IPDMS",
        y = "ISS"
      )
Ali Anis
  • 63
  • 6
  • 2
    It is impossible to help you if you don't provide a minimal reproducible exemple for the community : https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Indeed, we need to know what is IPDMS, you should edit your post with the output of `dput(IPDMS)`which should be something like `IPDMS=structure(...)` – Basti Jul 21 '21 at 09:12
  • For setting scale limits on ggplot You can use for example `xlim(1,1)` . Check this website and find your own solution: https://ggplot2.tidyverse.org/reference/lims.html – KacZdr Jul 21 '21 at 09:17
  • @BastienDucreux IPDMS is the different values of the axe X [ 0.78 , 0.81, 0.83, 0.89 ... etc] – Ali Anis Jul 21 '21 at 09:19
  • A tip that might help you on your 2nd point, if you want to customize your axis, have a look at `scale_x_continuous()` and `scale_y_continuous()` functions. Arguments `breaks` and `limits` might do the trick. – Paul Jul 21 '21 at 09:37
  • @AliAnis, to share you data, please could you copy/paste the output of `dput(df)`? The data you shared is a list, and list can not be used with ggplot. In addition, is seems there is a typo, `IPDMS` has 22 elements while `Indice_Server` has 21 – Paul Jul 21 '21 at 09:43
  • Okey, sorry, i will add it now i'm working on – Ali Anis Jul 21 '21 at 09:55
  • @Paul here's the data i think it works – Ali Anis Jul 21 '21 at 10:09
  • @tjebo No :/ it's doesn't work – Ali Anis Jul 21 '21 at 10:26
  • @AliAnis still not working... It seems like there is still a typo in the code you included in your question. i.e I get errors telling that `)` is unexpected – Paul Jul 21 '21 at 10:26
  • @Paul i found the error, i edit the post, can u try now pls ? – Ali Anis Jul 21 '21 at 10:38
  • @AliAnis it works thanks. We can see they are some problems with your data: `IPDMS` and `Indice_Sever` are factors, I think you need them to be numeric or integer. – Paul Jul 21 '21 at 10:43
  • @Paul i set them in numeric but still the axes start in (0;0) – Ali Anis Jul 21 '21 at 10:47
  • It is normal that axes starts at (0 ; 0), This is linked to your coordinate system. If I understand correctly, you want to display two lines that highlight some area in your plot. You can use `geom_hline()` and `geom_vline()` to do so. In addition, it is not recommended to get axis ticks in the plot area (see https://stackoverflow.com/a/62393903/10264278 for more info). – Paul Jul 21 '21 at 10:52

1 Answers1

1

As mentionned in comments, I propose you use geom_hline and geom_vline along with scale_*_numeric and coord_cartesian to custom you plot. This post has very good tips in it.

ggplot(df, aes(x = as.numeric(IPDMS), y = as.numeric(Indice_Sever), label = label, group = 
                 Finess)) + 
  # add "fake axis" to highlight something (your 1st point)
  # it is considered as a good practise to leave axis labels outside plot area so they can
  # not be mistaken with other labels related to your points for ex.
  geom_hline(yintercept = 1) +
  geom_vline(xintercept = 1) +
  # Custom axis limits/range without loosing data
  coord_cartesian(xlim = c(0, 1.5), ylim = c(0, 1.5)) +
  # Change axis ticks labels
  scale_x_continuous(name = "IPDMS",
                     breaks = seq(from = -1, to = 2, by = 0.2)) +
  scale_y_continuous(name = "Indice Server",
                     breaks = seq(from = -1, to = 2, by = 0.2))

Output:

enter image description here

You can play around with these parameters to get what you want with your actual dataset.

Paul
  • 2,850
  • 1
  • 12
  • 37