This question already has answers here:
How to change legend title in ggplot
(14 answers)
Closed 4 years ago.
I used R and ggplot to do a small-multiple graph.
ggplot(data=datatest,aes(x=Percentage,y=Accuracy,group=interaction(Classifiers, Feature), color=interaction(Classifiers, Feature)))+geom_line()+facet_grid(OS ~ Dataset)
The graph I got is:
How can I remove change the legend, for example, I want to change interaction(Classifiers,Feature) to just 'Approaches', and also, how to change like SVM.Ngram, LG.WE, SVM.WE to just 'approach1','approach2', and 'approach3'.
Try
tbl <- c(
SVM.Ngram = "approach1",
LG.WE = "approach2",
SVM.WE = "approach3"
)
ggplot(data=datatest,
aes(x=Percentage,y=Accuracy,group=interaction(Classifiers, Feature), color=interaction(Classifiers, Feature))) +
geom_line() +
labs(color = "Approaches") +
facet_grid(OS ~ Dataset, labeller = labeller(tbl)
)
This is from http://ggplot2.tidyverse.org/reference/labeller.html - if you check there, it gives more options you might be interested in.
Related
This question already has answers here:
Show frequencies along with barplot in ggplot2
(5 answers)
Closed 8 years ago.
I want to plot frequency distribution of an [r] factor variable as a bargraph, where bars represent the frequency counts of the factor levels. I use ggplot2 to do that and there's no problem with that.
What I can't figure out is how to add frequency count labels to the bars in the bargraph. The syntax that I've tried is as follows:
ggplot(data, aes(x = factorvar)) + geom_bar(fill = "somecolor") + geom_text(aes(y = ???))
I think I thoroughly searched in stackoverflow and "R Graphics Cookbook" by W.Chang but I couldn't find any specific answer to what parameter should I match to "y" in the aesthetics of geom_text() above. I tried some variants like: (y = ..count..) but it didn't work.
I would appreciate any help. Thanks...
ggplot(data=diamonds, aes(x=clarity)) +
geom_bar() +
geom_text(stat='count', aes(label=..count..), vjust=-1)
This question already has answers here:
Ignore outliers in ggplot2 boxplot
(8 answers)
Closed 4 years ago.
I am trying to Boxplot my data frame using this command.
ggplot(combined_data,aes(x= factor(field), y=moisture1))+geom_boxplot()
How can I remove the outliers from the output of this command ?
If you just want to remove the outliers from your graph, you can just add the argument outlier.shape = NA to geom_boxplot()
Example:
require(tidyverse)
mtcars %>%
ggplot(aes(1, wt)) +
geom_boxplot(outlier.shape = NA)
This question already has answers here:
Add legend to ggplot2 line plot
(4 answers)
Closed 4 years ago.
Probably very basic question about the legends in ggplot2 (sorry i am basic user user of R), I use this:
p<-ggplot(bAfr_topS1, aes(MAF, V3))+ geom_point()
p <- p+ geom_point(data=bEur_topS1,aes(MAF,V3),colour="red")+
geom_point(data = bSas_topS1, aes(MAF, V3), colour="blue")
print(p)
but can't see the legends in output plot, any suggestion please? what should i add in?
It's difficult to give specific help without any data, but to illustrate the point #PoGibas is making and to get you started, try the following
library(tidyverse)
bind_rows(list(AF = bAfr_topS1, EU = bEur_topS1, PK = bSas_topS1), .id = "src") %>%
ggplot(aes(MAF, V3, colour = as.factor(src))) +
geom_point()
This assumes that bAfr_topS1, bEur_topS1, bSas_topS1 all have the same column structure.
This question already has answers here:
Show frequencies along with barplot in ggplot2
(5 answers)
Closed 8 years ago.
I want to plot frequency distribution of an [r] factor variable as a bargraph, where bars represent the frequency counts of the factor levels. I use ggplot2 to do that and there's no problem with that.
What I can't figure out is how to add frequency count labels to the bars in the bargraph. The syntax that I've tried is as follows:
ggplot(data, aes(x = factorvar)) + geom_bar(fill = "somecolor") + geom_text(aes(y = ???))
I think I thoroughly searched in stackoverflow and "R Graphics Cookbook" by W.Chang but I couldn't find any specific answer to what parameter should I match to "y" in the aesthetics of geom_text() above. I tried some variants like: (y = ..count..) but it didn't work.
I would appreciate any help. Thanks...
ggplot(data=diamonds, aes(x=clarity)) +
geom_bar() +
geom_text(stat='count', aes(label=..count..), vjust=-1)
This question already has answers here:
ggplot2: change order of display of a factor variable on an axis
(2 answers)
Avoid ggplot sorting the x-axis while plotting geom_bar()
(6 answers)
Closed 7 years ago.
here is an example of my data:
test = data.frame(month_year = c("MAR13","APR13","MAY13","JUN13"),
turnover = c(10,15,25,10))
Here is my plot:
ggplot(data = test,
aes(x = month_year,
y = turnover,
group = 1))+
geom_line()
Now my question is why is the X-axis sorted alphabetically and how can I prevent it, because as you can see it makes no sense.
Thank you!
Just use :
test = data.frame(month_year = factor(c("MAR13","APR13","MAY13","JUN13"),levels=c("MAR13","APR13","MAY13","JUN13")),
turnover = c(10,15,25,10))