我有一个data.frame单条记录和一个 N 数字列。我想R在ggplot.
例如:
df <- data.frame(a=1, b=0, c=10, d=20)
Run Code Online (Sandbox Code Playgroud)
我调换了data.frame但没有设法命名两列。
注意:虽然 Python 实现了相同的图sns:
sns.barplot(x = 'Name', y = 'count', data*)
Run Code Online (Sandbox Code Playgroud)
在基础 R 中,这很简单
barplot(unlist(df[1, df[1, ] != 0]))
Run Code Online (Sandbox Code Playgroud)
如果你更喜欢ggplot2图形,
library(tidyverse)
df %>%
gather(key, value) %>%
filter(value != 0) %>%
ggplot(aes(x = key, y = value)) +
geom_col()
Run Code Online (Sandbox Code Playgroud)