-1

I´m making a simple scatter chart using ggplot. This is my data (GDJan):

  Name    DNN     DSIDM   DIDMM  Result                  
  <chr>  <dbl>   <dbl>  <dbl> <chr>                    
1 RS     -11    -32.9   0.473 NNC
2 MA      -9    -39.5   0.160 NNC
3 P        0     -5.7  -0.335 QNC
4 Q       34    132.0  -1.06  NNS

I would like to set the x axis (DIDMM) between -3 and 3. Also set the y axis (DNN) between -15 and 40.

That is my code:

ggplot(data = GDJan, mapping = aes(x = DIDMM, y = DNN)) +
+ geom_point() +
+ geom_label(aes(label = Indice))

Sorry if this question is too simple, I did a reseach here and on internet but all the related answers I found were for complicated charts. I´m learning, very new using R. I hope someone can help or show me where can I find a answer.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Have you tried `lims`, `xlim`, or `ylim`, or even setting a `limits=` argument in any individual scales (e.g., `scale_x_continuous`)? – r2evans Jul 11 '18 at 15:09
  • use `+ scale_x_continuous(limits = c(-3, 3) + scale_y_continuous(limits = c(-15, 40))` – RLave Jul 11 '18 at 15:10

2 Answers2

1

Please make sure you use a reproducible example next time.

The geom_label() cannot work as Indice is not an object that you defined anywhere.

library(ggplot2)

GDJan <- data.frame(Name = c("RS", "MA", "P", "Q"),
                    DNN = c(-11, -9, 0, 34),
                    DSIDM = c(-32.9, -39.5, -5.7, 132),
                    DIDMM = c(0.473, 0.160, -0.335, -1.06),
                    Result = c("NNC", "NNC", "QNC", "NNS"))

ggplot(data = GDJan, mapping = aes(x = DIDMM, y = DNN)) +
  geom_point() +
  ylim(c(-15, 40)) +
  xlim(c(-3, 3))
roming
  • 1,165
  • 1
  • 9
  • 22
0

Adding the line

 +lims(x = c(-3,3), y = c(-15,40))

should do the trick