R: plotROC main title cannot be changed from default - r

I use the plotROC from hmeasure-package to (try to) plot an ROC curve. I get a plot like shown below. The code I used is:
require(hmeasure)
predictions_LIMO <- data.frame(df)
h_LIMO <- HMeasure(mydata$churn, predictions_LIMO)
plotROC(h_LIMO,which=1)
If I try to customize the main title, I get the two titles overlapping each other, like shown in the lower picture. The additional code is:
title("ROC curve for LIMO4 to LIMO8")
Is there a way to get rid of the automatically assigned title? I tried main=0 but received unused argument (main = 0).
In the ?plotROC I did not find anything about that.
Thanks for any advice (maybe also on different packages that I can use to circumvent the problem)!

As #joran said, it's hard-coded. Here's a quick hack if you don't want to mess with the plotROC function. You can "cover" the existing title with a white rectangle and then add your own title. For example:
# Adjust location of rectangle as needed. These coordinates should work
# for the graph you posted.
rect(0, 1.1, 1, 1.7, xpd=TRUE, col="white", border="white")
title("My Title")

Related

R Make barchart with unicode symbol instead of bars

I'd like to plot a (kind of) barchart, but rather than using bars, I'd like to use a unicode symbol. Is this possible?
I know how to use a unicode character as a symbol (points); for example:
plot(1,1,pch=-0x0001F3E2, cex=5, col="gray30")
but how can make the symbol substitute the bars?
EDIT:
As suggested by Eric, I'll try to write a minimal reproducible example...
Given variable x:
x <- c(2,3,4,2,1)
barplot(x)
I want to produce a barplot using custom symbols rather than bars. Something like:
plot(1:5,rep(0,5),pch=-0x0001F3E2, cex=x, col="gray30")
The problem is that I am not able to vertical align sysmbols as I can do with text:
plot(1:5,rep(0,5),type="n", ylim=c(0,1),bty="n")
text(1:5,0,"A",cex=c(2,5,3,3,1),adj=c(0.6,0))
So, a sort of solution to my problem, although not ideal, is to use
some custom system font with package extrafont.
For example, using font "Destiny's Little Houses" (http://www.dafont.com/destiny-little-hous.font)
I am able to produce some nice infographics:
plot(1:5,rep(0,5),type="n",ylim=c(0,1),bty="n")
text(1:5,0.1,"A",cex=c(2,5,3,3,1),adj=c(0.6,0),family="Destiny's Little Houses")
So, rather than having bars I have an image whose size changes according to some variable (using "cex").
This is not ideal, first of all because I'd like to be able to import any image (ex. using the png package).
So, is it possible to:
import an image file and use it as the symbol in plot (rather than one of the available sysmbols using pch)?
Vertical align symbols so that I get a kind of custom barchart?
Thanks
António
Here's a somewhat hackish start (might not be helpful as I don't know what your data looks like).
counts <- table(mtcars$gear)
foo <- barplot(counts, col = c("white", "white", "white"), border=c("white"), axes=F, xaxt="n")
points(foo, counts-.5, pch = -0x0001F3E2, cex=2, pos=3)
Remove , axes=F, xaxt="n" to get the labels and axis back.

R: Boxplot - how to move the x-axis label down?

#RGR ~ Treatment:Geno boxplot
fit <- aov(Total.RGR~Treatment:Geno, data=For.R)
summary(fit)
t <- TukeyHSD(fit)
t
boxplot(Total.RGR~Treatment:Geno,
data=For.R,las=2,ylim=c(-20,100),xlab="Treatment:Geno",ylab="RGR (mg/day)")
text(1:8, 95 ,c("a","ac","a","a","a","bd","bcd","ad"))
Is my code, it does the job, but when I rotate my x-axis labels the obstruct the x-axis title.
Does any of you know of a way to move the title down?
It must be easy but I cant find anything in the reference.
Thanks.
Mathias
I would set xlab="" and add it afterwards using mtext. So, either you play with line parameter an put it the bottom under your lables Or change completely the side to put it in the top of the plot.
mtext("Treatment:Geno", side=1, line=5)
mtext("Treatment:Geno", side=3)

How to plot just one axis label in R?

A beginner question: I currently have some plots that look like this.
I'm keeping the plots free of other annotation because I have to fit a lot of them onto one page and specific values aren't important, just the general trend that the red line is to the right of the black one. However, I'd like to be able to indicate that the dashed line in my plot actually represents zero, like so:
Is there any way to tell R to only display that value on the x-axis labels? I don't think using text() would be a good idea because it relies on absolute coordinates, but I'm not really sure how to work with axis options to make it do what I want.
Try:
axis(side = 1, at = 0)
See ?axis for details.

barplot design issues

I am doing a barplot of 14 columns to represent some data, I set the names.arg option to show as vertical lables, unfortunately, this caused the new vertical lables to overlap with the "sub" and "xlab" options I have. How do I prevent this from happening?
Here's my command:
par(mar=c(6, 5, 4,7.5 ))
barplot(x, main=paste("title1 \n","subtitle"),
names.arg=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14),las=2, sub=("overlapping text1"),
xlab="overlapping text2", col = c("red2","darkorange3"))
Another question on my mind is, I am using a 2-line title in "main" as you can see from the command. Is it possible to make the second line font smaller, whilst keeping the first line in the same format?
Thanks,
One solution to change font size for one of titles, is to use two calls of functions mtext() in different lines with different cex= values and remove main= from barplot(). To overcome problem with overlapping text, mtext() also can be used instead of xlab= and sub=. You just have to find the right line= and increase space around plot with par(mar=..).
x<-sample(letters[1:14],300,replace=TRUE)
par(mar=c(9,3,5,2))
barplot(table(x),
names.arg=paste0("very_long_",1:14),las=2,
col = c("red2","darkorange3"))
mtext(side=3,"Title1",line=2,cex=2)
mtext(side=3,"subtitle",line=1,cex=1.5)
mtext(side=1,"overlapping text1",line=6)
mtext(side=1,"overlapping text2",line=7)
Another option to look at is the staxlab function in the plotrix package.
Also look at the mgp argument to the par function for a way to set the default placement of the axis title.

Specify plot area in a multiplot

I create a row of plots in a graphic device with the par() command and run the first 2 plots:
par(mfrow = c(1, 4))
hist(mydata)
boxplot(y ~ x)
Now let's say the boxplot is wrong and I want to replace it with a new one. By default the next plot goes to the left side of the previous one (or one row below, first column, in case of a multiple rows layout), leaving the previous plot unchanged.
Is there a way to specify the location of the next plot in the multiplot grid area?
To specify the location of the next plot in the multiplot grid area, I prefer to use the function layout.
The layout function provides an alternative to the mfrow and mfcol settings.
For example the equivalent of par(mfrow = c(1, 4)) is :
layout(matrix(c(1, 3, 2, 4), byrow=TRUE, ncol=4))
or
layout(matrix(c(1, 2, 3, 4), byrow=TRUE, ncol=4))
The function layout.show() may be helpful for visualizing the figure regions
that are created. The following code creates a figure visualizing the layout
created in the previous example:
layout.show(4)
The base graphics model is ink-on-paper and does not allow revisions. The lattice and ggplot models are based on lists that can be modified. You can "go back" an add items with lines, points and as pointed out you can change the focus to a particular panel, but to remove or replace stuff .... not possible. Re-running the code shouldn't be a big problem, should it? Pixels are very cheap.
You can specify the next frame to plot to useing the mfg argument to par. See ?par for details. So a command like:
par(mfg=c(1,2))
Will mean that the next high level plot will go to the plot in the 1st row 2nd column. This can be used to plot in your own custom order. However, using layout for this is probably easier better in most cases.
When you use this to specify a frame to plot in R assumes that the frame is ready to be plotted in, it will not remove anything already there, so if there is an existing plot there it will be plotted over and you will likely see both plots and it won't look pretty.
You can draw a rectangle over the top of an existing plot to give yourself a blank frame to plot in using code like:
par(xpd=NA)
rect( grconvertX(0, from='nfc'), grconvertY(0,from='nfc'),
grconvertX(1,from='nfc'), grconvertY(1, from='nfc'),
col='white',border='white')
This works OK for looking at on the screen, but you need to be careful with this if exporting or printing, in some cases the printer or interpreter of the graphics file will interpret the white rectangle as "do nothing" and you will again see both plots.
In general it is best to do plots that take more than a line or 2 of code in a script window so that if you want to change something you can edit the script and just recreate the whole plot from scratch rather than relying on tricks like this.

Resources