![](/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.