This question already has answers here:
Reorder levels of a factor without changing order of values
(9 answers)
Closed 9 years ago.
I have created a plot of coverage vs gene. I would like to plot the genes (x axis) from lowest coverage value (y axis) to largest. I used the function "plot" but it automatically sorts the gene names from lowest to highest. How do I arrange them from lowest coverage to highest instead?
Maybe switch the ylim:
plot(1:10, ylim=c(10,1))
Related
This question already has answers here:
Plot each column against each column
(2 answers)
Plot all pairs of variables in R data frame based on column type [duplicate]
(1 answer)
Closed 17 days ago.
I have the output of 3 different algorithms as a continuous vector. Instead of comparing their correlation 1 by 1, I would like to plot them all simuntaionusly in the same plot, but in different panels. The dataframe looks like this (but contains >10k ids):
df <- data.frame(id=1:5,
feature1=runif(5),
feature2=runif(5,min = 3,max=5),
feature3=runif(5, min = 5,max=8))
Ideally, the resulting plot should looks something like this:
I am fairly sure that there is some simple tidyr function, which expands my dataframe in such a way that I can simply use ggplot2 in combination with facet_grid, but I searched and coudn't find anything..
Any help is much appreciated!
This question already has answers here:
Order Bars in ggplot2 bar graph
(16 answers)
Reorder bars in geom_bar ggplot2 by value
(3 answers)
ggplot2 geom_bar - how to keep order of data.frame [duplicate]
(1 answer)
Closed 1 year ago.
I'm trying to do a barplot where entries of the same factor are next to eachother so I can compare (in this example I want to compare the tissue type).
I sort the dataframe but for some reason ggplot does not follow the sorting.
tp <- ms %>%
arrange(tissue) %>%
mutate(tissue=as.factor(tissue))
ggplot(tp) +
geom_bar(aes(x=Sample, y=!!sym(cv), fill=tissue), stat="identity") +
ylab("")
head(tp$tissue)
and I check and i know that tp is sorted
head(tp$tissue) outputs
[1] adjacent adjacent adjacent adjacent adjacent adjacent
Levels: adjacent normal tumor
This question already has answers here:
Order Bars in ggplot2 bar graph
(16 answers)
Remove all of x axis labels in ggplot [duplicate]
(1 answer)
Closed 2 years ago.
I have a dataframe DiatomFiltered containing the column species. I want to have a ggplot (ggplot2) of all species and their frequency ordered from highest to lowest. The below code works, but the names are a mess (because of way too many species names) so I want to remove that and i want the frequencies ordered. How do i do this?
ggplot(DiatomFiltered, aes(species)) +
geom_bar(fill = "#0073C2FF")
This question already has answers here:
Boxplot sees values that aren't there
(1 answer)
How to remove ticks and labels of dropped off factors in a box plot
(1 answer)
Closed 5 years ago.
You can see my plot in this link.
I want to remove the first three points from the x axis, so I only display data from "2.31-52k", "1.52-100k", "3.18-31k", "4.<18k", "0.>100k". And not -1.0,-3.1 etc.
I have managed to remove the data to produce this graph, by creating a subset in dAll$income and assigning it to a new data frame with the following code.
new_df = subset(dAll, subset = dAll$income %in% c("2.31-52k", "1.52-100k", "3.18-31k", "4.<18k", "0.>100k"))
However when I plot this, the values remain on the x axis.
This question already has answers here:
How to create grouped barplot with R [duplicate]
(1 answer)
plotting grouped bar charts in R
(3 answers)
Closed 3 years ago.
I have a data table with two small columns.
I want to do a pairwise comparison between the values. The first column is results of one test and the second of another test. So I want a barplot where the first pair of bars show value [1,1] and next to it [1,2] then [1,2] besides [2,2] and so on.
I have 20 values (10 in each from 10 instances) and want 20 bars in one plot. I have no category variable but I want to preserve the order in which they appear in the column (each result corrosponds to an instance). Hence 20 values represented by 20 bars.
Hope you can help.
Edit: Sry for the bad explanation.
Based on your vague question I think this is what you want. Here is a quick example you can use to get your results:
counts <- table(mtcars$vs, mtcars$gear)
barplot(counts, main="Car Distribution by Gears and VS",
xlab="Number of Gears", col=c("darkblue","red"),
legend = rownames(counts), beside=TRUE)
Source: http://www.statmethods.net/graphs/bar.html