问题
I am trying to write a code by using dplyr and a yeast dataset
I Read in the data with this code
gdat <- read_csv(file = "brauer2007_tidy1.csv")
I ommitted na's by using this
gdat <- na.omit(gdat)
library(ggplot2)
Then I tried to filter some genes according to their column name "symbol" and used ggplot to make a plot
filter(gdat, symbol=="QRI7", symbol== "CFT2", symbol== "RIB2",
symbol=="EDC3", symbol=="VPS5", symbol=="AMN1" & rate=.05) %>%
ggplot(aes(x=rate,
y=expression,
group=1,
colour=nutrient)) +
geom_line(lwd=1.5) +
facet_wrap(~nutrient)
facet_wrap(~nutrient) is used to seperate each gene's rate vs. expression graphs according to the nutrient which is depleted but this error keeps coming:
error: Faceting variables must have at least one value
I checked these genes by using the filter function if all of them could be displayed on r and they did when I filtered them individually but when I combine multiple genes with ggplot I get this error. Also when I use "&rate=.05" I can't get only the values which are at rate=.05. Does anyone know how I can fix this problem? I have a deadline till tomorrow 17.30 and if somebody could help me I would be very glad, thanks.
回答1:
I downloaded what I assume is the same dataset like this:
library(readr)
library(dplyr)
library(ggplot2)
gdat <- read_csv("https://raw.githubusercontent.com/bioconnector/workshops/master/data/brauer2007_tidy.csv")
So the first problem is your filter
. If you are looking for any of those gene symbols, you need to use %in%
. And rate
requires a double equals ==
:
gdat %>%
filter(symbol %in% c("QRI7", "CFT2", "RIB2", "EDC3", "VPS5", "AMN1"),
rate == 0.05)
I don't think you want to filter for one rate and then use geom_line
, because you will just get one vertical line at one value of x (rate).
Neither do I think you want to use geom_line
for multiple values of rate
, because there are several values for expression
at each rate and a line will generate a nasty-looking zigzag.
And as you are faceting on nutrient, there's no need to color by nutrient. Perhaps you want to color by gene?
So you need to think about what makes a good visualisation of this data. Here's a simple example to get you started.
gdat %>%
filter(symbol %in% c("QRI7", "CFT2", "RIB2", "EDC3", "VPS5", "AMN1")) %>%
ggplot(aes(x=rate,
y=expression,
color = symbol)) +
geom_line() +
facet_wrap(~nutrient)
Result:
来源:https://stackoverflow.com/questions/65174194/error-filtering-data-faceting-variables-must-have-at-least-one-value