おそらく簡単なggplot2
質問です。
私が持っているdata.frame
とnumeric
値、カテゴリ(factor
)値、およびcharacter
値:
library(dplyr)
set.seed(1)
df <- data.frame(log10.p.value=c(-2.5,-2.5,-2.5,-2.39,-2,-1.85,-1.6,-1.3,-1.3,-1),
direction=sample(c("up","down"),10,replace = T),
label=paste0("label",1:10),stringsAsFactors = F) %>% dplyr::arrange(log10.p.value)
df$direction <- factor(df$direction,levels=c("up","down"))
これらのデータををbarplot
使用してプロットしたいと思いますgeom_bar
。ここで、バーは水平で、長さはdf$log10.p.value
、で、色df$direction
はで、y-axis
tick
ラベルはdf$label
で、バーは垂直に並べられていdf$log10.p.value
ます。
ご覧のdf$log10.p.value
とおり、一意ではありません。したがって、次のようになります。
ggplot(df,aes(log10.p.value))+geom_bar(aes(fill=direction))+theme_minimal()+coord_flip()+ylab("log10(p-value)")+xlab("")
どうすればよいですか:
y-axis
tick
ラベルがあることdf$label
?ありがとう
これが1つの可能な解決策です。デフォルトでgeom_bar
は、頻度/カウントを使用してバーの長さを決定することに注意してください。したがって、stat = "identity"
値のマッピングを指定する必要があります。
# since all of your values are negative the graph is on the left side
ggplot(df, aes(x = label, y = log10.p.value, fill = direction)) +
geom_bar(stat = "identity") +
theme_minimal() +
coord_flip() +
ylab("log10(p-value)") +
xlab("")
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加