Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

GGPLOT2 scale_x_discrete(labels = abbreviate) problem with october

$
0
0

Recently I tried to make monthly distribution of one value as a geom bar in GGPLOT. I have a problem with plots labels where for october it shows on X-axis 2019-1 instead 2019-10.

ggplot(data = temp.bk,aes(x = factor(excel_date), y = n)) +
  geom_bar(aes_string(fill = names(temp.bk)[3]),stat="identity",
           position = "dodge") +
  scale_x_discrete(labels = abbreviate)

My data is a tibble:

excel_date group value     n percent
   <date>     <chr> <chr> <int>   <dbl>
 1 2018-11-30 710   ge1   32385  0.960 
 2 2018-11-30 710   ge2     928  0.0275
 3 2018-11-30 710   ge3     416  0.0123
 4 2018-12-31 710   ge1   32568  0.962 
 5 2018-12-31 710   ge2     880  0.0260
 6 2018-12-31 710   ge3     392  0.0116
 7 2019-01-31 710   ge1   32455  0.965 
 8 2019-01-31 710   ge2     774  0.0230
 9 2019-01-31 710   ge3     389  0.0116
10 2019-02-28 710   ge1   32525  0.967 
11 2019-02-28 710   ge2     707  0.0210
12 2019-02-28 710   ge3     391  0.0116
13 2019-03-31 710   ge1   32539  0.968 
14 2019-03-31 710   ge2     739  0.0220
15 2019-03-31 710   ge3     350  0.0104
16 2019-04-30 710   ge1   32544  0.968 
17 2019-04-30 710   ge2     676  0.0201
18 2019-04-30 710   ge3     412  0.0123
19 2019-05-31 710   ge1   32520  0.967 
20 2019-05-31 710   ge2     702  0.0209
21 2019-05-31 710   ge3     411  0.0122
22 2019-06-30 710   ge1   32517  0.967 
23 2019-06-30 710   ge2     712  0.0212
24 2019-06-30 710   ge3     406  0.0121
25 2019-07-31 710   ge1   32561  0.968 
26 2019-07-31 710   ge2     663  0.0197
27 2019-07-31 710   ge3     411  0.0122
28 2019-08-31 710   ge1   32434  0.964 
29 2019-08-31 710   ge2     791  0.0235
30 2019-08-31 710   ge3     414  0.0123
31 2019-09-30 710   ge1   32572  0.968 
32 2019-09-30 710   ge2     648  0.0193
33 2019-09-30 710   ge3     417  0.0124
34 2019-10-31 710   ge1   32627  0.970 
35 2019-10-31 710   ge2     596  0.0177
36 2019-10-31 710   ge3     422  0.0125

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>