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…

26 Gedanken zu “R-Scripts

    1. Abderrahim schreibt:

      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


      1. 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.

    2. Abderrahim schreibt:

      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


      1. 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/

    3. Abderrahim schreibt:

      Many thanks. I used the function sjp.setTheme but I didn’t get what I wanted. May be I misused. The code was:
      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


      1. 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.

    4. Abderrahim schreibt:

      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


      1. Abderrahim schreibt:

        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


    1. 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…

  1. Catherine schreibt:

    Thank you for your script. I found it while trying to plot a linear mixed effects model (by maximum likelihood) of formula Disease_severity ~ Initial_severity + (Duration_yrs * Dementia) + (Duration_yrs * Age_Catagory) + Random effect of subject.
    Duration_yrs is continuous but Dementia and Age_Catagory are binary
    I am trying to use sjp.int to plot both interactions but get the error message Error in sjp.int(Disease_severity) : object ‘fun’ not found
    What is the missing object ‘fun’? How d I trouble shoot this?
    Is sjp.int able to simulaneously plot both interaction terms?

    Thank you!

Kommentar verfassen

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


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


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


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

Google+ Foto

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

Verbinde mit %s