R-Scripts

sjPlot package

All my R-scripts I published here (and even some more) are now available as bundled R-package! Please refer to the package page for downloads and more…

24 Gedanken zu “R-Scripts

    • Thank you very much for this fantastic package. Could you please tell me how can I use the “sjp.grpfrq” function but with percentage in the y-axis instead of absolute ferquencies. I wish to have absolute ferquencies between bracket. This is needed when one category has relatively more data than others.

      Many thanks

      Abderrahim

      • Hi Abderrahim,
        thanks for your feedback! Unfortunately, there’s no parameter to switch the scale to percentages. I’m not sure what kind of geoms you like to plot, but if you need bar plots, you can also use sjp.xtab instead.

    • Dear Daniel,

      So many thanks. This is what I needed exactly. Is there a possibility to put the legend inside the box when using sjp.xtab? my x-axis variable has 6 levels an each level has another 5 levels (the seconf factor) so when the legned is outside the plot does not look good.
      So many thanks

      Abderrahim

      • It’s not possible with the current version 1.5 on CRAN, however, I have re-written the plotting functions in version 1.6, where you can globally change theme options with the ‘sjp.setTheme’ function, which allows inside legend placement. You can either wait for the official update on CRAN or get the latest development snapshot from Github: https://github.com/sjPlot/devel/

    • Many thanks. I used the function sjp.setTheme but I didn’t get what I wanted. May be I misused. The code was:
      source(“sjp.setTheme.R”)
      sjp.setTheme(legend.inside=TRUE, legend.pos == “top right”)
      followed by my previous code i.e.:
      sjp.xtab(df_sub$country, df_sub$Risk, tableIndex=”row”, barWidth = 0.8, legendTitle = “Risk category”, barSpace = 0, ……)

      But the legend is still outside the box. Am I missing something?

      Best wishes

      Abderrahim

      • First you have to install the complete package from github (see read.me on github), because the sjp-functions have been rewritten and the new theme-options only work for the latest package on github (which will becom version 1.6 on CRAN). You need package devtools to install from github.

        Note that some parameter names have been renamed (barWidth is geom.size, barSpace is geom.spacing now).

        Then, use sjp.setTheme(legend.pos = "top right", legend.inside = T) and sjp.xtab(df_sub$country, df_sub$Risk, tableIndex=”row”, geom.size = 0.8, legendTitle = “Risk category”, geom.spacing = 0, ...).

        That should work.

    • That’s great. It works now. By the way, I modified the function “sjp.setTheme” to include a flexible legend position.By adding:
      else if (legend.pos == “user defined”) legend.pos <- legend_cord where "legend_cord" can be any vectors e.g. legend_cord = c(0.4,0.9). This allows me to put the legend anywhere I want in the graph!

      By the way
      1- how can I reduce/increase the size of the legend box with the new function sjp.setTheme?
      2- what are the equivalents (wrt the old version) of:
      – axisLabelSize.x
      – showTickMarks
      – axisLabelColor.x

      Many thanks

      Abderrahim

    • Great! so many thanks

      • Dear Daniel,

        Is there an option in xtab or theme to:
        1- have the percentage and count on each bar in a vertical format?
        In ggolot I can do that using: geom_text(aes(label = sprintf(“%.00f%% (n=%i)”,P_target, N_target)),angle = 90)

        Many thanks for your help

        Abderrahim

  1. Awesome scripts! Thanks for sharing that! How about submitting a package to cran?

    • I already tried to build a package, but I failed. When I have the time I will try to get deeper into package building and give it a new try…

  2. […] can download the script sjPlotInteractions.R from my script page. The function sjp.lmint requires at least one parameter: a fitted linear model object, including […]

  3. […] some struggling, I now managed to setup RStudio, Roxygen and MikTex properly so I can compile my collection of R-scripts into a package that even succeeds the package […]

  4. Congratulations for your excellent scripts..Very impressive very useful.Thanks.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ photo

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s