![](/img/trans.png)
[英]How to create base R plot 'type = b' equivalent in ggplot2?
[英]how to create this type of plot by 'ggplot2'
不是一个完整的解决方案,而是本质。
library(tidyverse)
library(ggplot2)
df <- tibble(
type = c("barley",
"maize",
"sunlower oil",
"wheat"),
ukraine = c(0.974, 0.1643, 0.4221, 0.0891),
russia = c(0.095, 0.0160, 0.2140, 0.1420)
)
# A tibble: 4 x 3
type ukraine russia
<chr> <dbl> <dbl>
1 barley 0.974 0.095
2 maize 0.164 0.016
3 sunlower oil 0.422 0.214
4 wheat 0.0891 0.142
df %>%
gather(-type, key = "country", value = "value") %>%
ggplot() +
aes(x = type, y = value, fill = country) +
geom_col() +
coord_flip()
ggplot2 基本上用于使用图形创建优雅的数据可视化。
这是示例:
library(ggplots2)
ggplot2(dataset, aes(x='dataset_col1', y='dataset_col2')
这里我们得到dataset_col1 (x axis)
和dataset_col2(y-axis)
输出
在运行此代码之前,您需要从包中下载包 -> ggplot2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.