leeper / cregg

Simple Conjoint Analyses, Tidying, and Visualization
Other
50 stars 7 forks source link

Color change #26

Closed pdwaggoner closed 5 years ago

pdwaggoner commented 5 years ago

Please specify whether your issue is about:

See below for these things. I just copied and pasted the example for MM's from the package README.

I was curious if you could change the colors to gray scale, for example, instead of rainbow colors for journal publication? Couldn't figure out how to do this. Thanks!

Example here:

## load package
library("cregg")

data("immigration")

# taken from README
f1 <- ChosenImmigrant ~ Gender + Education + LanguageSkills + CountryOfOrigin + Job + JobExperience + JobPlans + ReasonForApplication + 
    PriorEntry
plot(mm(immigration, f1, id = ~CaseID), vline = 0.5) # change colors here?

## session info for your system
sessionInfo()

# OUTPUT:
### R version 3.5.2 (2018-12-20)
### Platform: x86_64-apple-darwin15.6.0 (64-bit)
### Running under: macOS Mojave 10.14.3
mbarnfield commented 5 years ago

Hi, I'm pretty sure scale_colour_grey this does the trick. If you're using RStudio and it looks weird in the plots viewer, click the zoom button and look at it that way to check.


library(tidyverse)

data(immigration)

# specify formula
f1 <- ChosenImmigrant ~ Gender + Education + LanguageSkills + CountryOfOrigin + Job + JobExperience + JobPlans + ReasonForApplication + 
  PriorEntry

# create plot object 
p <- plot(mm(immigration, f1, id = ~CaseID), vline = 0.5)

# adjust visuals
p +
  scale_colour_grey() + 
  theme_bw()
  theme(legend.position = "right")

The last two lines aren't necessary, but I think it looks better with them. That is, p + scale_colour_grey() should be fine on its own. Equally you can do it without saving the plot object of course:


library(tidyverse)

data(immigration)

# specify formula
f1 <- ChosenImmigrant ~ Gender + Education + LanguageSkills + CountryOfOrigin + Job + JobExperience + JobPlans + ReasonForApplication + 
  PriorEntry

# calculate mms
mm_immigration <- mm(immigration, f1, id = ~CaseID)

# create plot object 
plot(mm_immigration, vline = 0.5) + 
  scale_colour_grey()
leeper commented 5 years ago

Exactly. It’s a ggplot2 object so you can just + whatever further modifications you want to it. You may need to use an aes() if you want to change shape, fill, etc. rather than colour.

pdwaggoner commented 5 years ago

Brilliant - many thanks for the help here! And many thanks @leeper for the great package; super useful and simple to use.