Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am plotting multiple ROC-curves with ggroc, and would like the axis names to be "True positive rate" and "False positive rate", rather than sens and spec. Is it possible to do this with ggroc?
I have already tried the following which didn't work:
library(pROC)
ROC_curves <- ggroc(list(log=ROC_log, tree=ROC_tree, rf=ROC_rf), aes(TPR, FPR), legacy.axes=TRUE)
I have also tried this:
ROC_curves <- ggroc(list(log=ROC_log, tree=ROC_tree, rf=ROC_rf), legacy.axes=TRUE) + scale_x(name="FPR") + scale_y(name="TPR)
ggroc returns a standard ggplot object, so you can change the axis labels and everything exactly as you would for a standard ggplot:
ggroc(list(log=ROC_log, tree=ROC_tree, rf=ROC_rf), legacy.axes=TRUE)
ROC_curves + xlab("FPR") + ylab("TPR")
Note that you are using legacy.axes=TRUE so that you can re-label the axis this way. Make sure to keep this argument, otherwise the labeling would be invalid.
Also you can drop the aes(TPR, FPR) which is silently ignored.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have a a dataset such as follows:
CON <- data_frame(norm.d.2=c(1.37,1.11,1.84),CDSex.=c(0.439,0.335,0.432))
I am plotting this data frame with ggplot2, but I am unable to change the x axis labels. I have tried both scale_x_continuous and scale_x_discrete, but either I receive an error or no labels at all.
ggplot(CONrc,aes(x=norm.d.2,y=CDSex.)) +
geom_point(aes(color=factor(interaction(hpi,rep)))) +
xlab('Exonic % of Cellular Reads') +
ylab('CDS % of Exonic Reads')
When I try scale_x_continuous(breaks=c(0.5,1.5,2.5)), I get the following error:
Error: Discrete value supplied to continuous scale
When I try scale_x_discrete(breaks=c(0.5,1.5,2.5)), I do not get an error message, but my plot loses all x axis labels.
looks fine for CON table.
try to mutate CONrc
CONrc$norm.d.2 <- as.double(CONrc$norm.d.2)
and then plot this
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to plot a box-plot with ggplot2 using the Wage database in the ISLR package. The box-plot is meant to visualize the Wage versus educational level, which is presented in five categories. When I try to use the typical code to generated the box-plot a get the following warning from Rstudio:
Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (3000): y
My code is
library("ISLR")
library("MASS")
setwd("C:/Users/Alonso/Desktop/ITSL")
View(Wage)
ggplot(Wage, aes(x=education, y=Wage))+
geom_boxplot(outlier.colour="red", outlier.shape=8, outlier.size=4)+labs(x="Nivel de estudio", y="Salario")
I have made other graphics but just with numeric variables, maybe the problem is that now I am using a categorical variable. Any ideas?, thanks in advance and greetings from Chile.
You were almost there, just needed a lowercase y=wage because the column name is wage and not Wage.
ggplot(Wage, aes(x=education, y=wage))+
+ geom_boxplot(outlier.colour="red", outlier.shape=8, outlier.size=4)+labs(x="Nivel de estudio", y="Salario")
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am beginner in R and i have a simple regression. Now i want to plot the equation of the regression line into the plot. The most easiest way. I already tried to get it done by following some ideas here.
DICE_Quartal<-read.csv("")
attach(DICE_Quartal)
plot(Preise.Fernbusmarkt ~ Auskunftpflichtige.Unternehmen) + abline(cor_preis_unternehmen, col = "red")
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I simulate some data with R code and want to plot these data.
scatter plot is no problem with code plot(SX,Quant),
but when I use plot(SX,Quant,type='l'), the result is
I just want the line through every point.
I try different type of plot, also use ggplot2 to try to modification,
but has same result, plz help me to solve this problem.
Sort your data by the x-value of your plot:
F_inverse=function(x) log((exp(1)-1)*x+1)
U = runif(100)
SX = F_inverse(U)
Quant=rank(SX)/100
ord <- order(SX)
SX <- SX[ord]
Quant <- Quant[ord]
plot(SX,Quant, type="l")
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have built a wrapper for ggplot, and would like to enable the user of this to turn on or off certain elements. For example, in some plots the user will want to set the y-axis minimum to 0, while in others they will not.
What I want to be able to do, in this case, is have the user pass the 'ymin' variable to the function as T or F. If T, then the following element should be added to the chart.
+ expand_limits(y=0)
Is there a simple way to achieve this? Or is there an entirely different approach to this kind of problem that I should be using?
mathematical.coffee has pushed me in the right direction. Here is an elaborated answer.
plot <- ggplot(data=data, aes(...))+
geom_line()
if(ymin == T)
{
plot <- plot + expand_limits(y=0)
}
You could wrapp the your ggplot in a function, where you parameter are optionally. If no parameter are provided to the function, the assigned value in the signature is used
plotWithLimits <- function(y=0, data, ...) {
return ggplot(data=data, aes(..)) + geom_line()+expand_limits(y=0)
}