[R] "patternbar_s" : show legend and other issues

John m|@ojpm @end|ng |rom gm@||@com
Tue Aug 18 08:51:59 CEST 2020


Hi

   Thanks for help from people on this forum. My graph (made with
patternbar_s) is attached.

(1) How should I place my legend under the graph? I have "
,legend.position="bottom"" in my theme, but it does not seem to work.
(2) How may I rotate the y label ("%")?

*****
Code:
*****
x<- factor(df_c_m$date)
df_c_m[,"date"]<-x
y<-df_c_m$percentage
group <- df_c_m$direction
patternbar_s(df_c_m, x,y, group, xlab='', ylab='%', label.size=3,
pattern.type=c( 'hlines','nwlines', 'crosshatch'), pattern.line.size=c(5,
5, 5),frame.size=0.2,
             pixel=16, density=c(18, 30, 50),frame.color='black',
              legend.label=c("up", "uc", "dn" ),
             bar.width=0.8)+scale_y_continuous(limits = c(0,
100.2))+ggtitle('')+ theme(axis.text.x = element_text(angle = 90),
aspect.ratio= 0.4 ,legend.position="bottom")
*****
data
*****
> dput(df_c_m)
structure(list(date = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L), .Label =
c("2019M08",
"2019M09", "2019M10", "2019M11", "2019M12", "2020M01", "2020M02",
"2020M03", "2020M04", "2020M05", "2020M06", "2020M07"), class = "factor"),
    direction = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("up1",
    "uc1", "dn1"), class = "factor"), percentage = c(71.7513561370186,
    75.2473091137506, 73.7487862435345, 72.4125114725349, 72.3916275654038,
    73.4317730346588, 72.0937990292721, 65.8525321274626, 53.9438308698102,
    49.8419388830348, 64.9068322981366, 64.4190871369295, 26.5388171383608,
    22.6579666815841, 24.5003031345886, 25.8702634409608, 25.9690881672084,
    25.2481298705291, 25.2724001268317, 27.6526752244884, 33.4526425872838,
    41.622760800843, 31.4699792960663, 32.5726141078838, 1.70982672462062,
    2.09472420466537, 1.75091062187687, 1.71722508650425, 1.63928426738778,
    1.32009709481208, 2.63380084389626, 6.49479264804901, 12.603526542906,
    8.53530031612223, 3.6231884057971, 3.00829875518672)), row.names =
c(NA,
-36L), class = "data.frame")


More information about the R-help mailing list