jaredlander / coefplot

Plotting model coefficients
Other
27 stars 19 forks source link

Removing the Factor's Name from the Plot #8

Open vsaulys opened 10 years ago

vsaulys commented 10 years ago

Found an easy way to remove the base factor name when plotting only the coefficients of a factor:

since this is ggplot2, I can just add a function to label the y axis that removes the factor name that appears in the beginning of the coefficient. It uses the str_replace function from stringr.

coefplot(model, sort = "magnitude", predictors = iPredictor, decreasing = FALSE) + scale_y_discrete(label=function(x) { str_replace(x, iPredictor, "") } )

Perhaps this can be added into the codebase to do this automatically?

jaredlander commented 10 years ago

Doing a straight up replace can be problematic in edge cases such as a factor called iPredictor and a continuous variable called iPredictors.

For now, check out the newNames argument which lets you specify new names for specific coefficients.