[英]technical difference between geom_bar and geom_linerange
使用 ggplot2 進行試驗時,我注意到 geom_bar/geom_col 和 geom_linerange 之間的圖形輸出存在差異。 一旦我將這些函數與 coord_polar(創建餅圖或圓環圖)結合使用,前兩個輸出就會被像素化,而 geom_linerange 會產生平滑的線條。
我很好。 我仍然想知道為什么以及在創建輸出的過程中會出現這種差異?
d <- dplyr::tibble(GRP=c("A","B","C"),
VAL=c(20,30,50))
p1 <- d %>%
ggplot2::ggplot(ggplot2::aes(x=2,y=VAL,fill=GRP)) +
ggplot2::geom_bar(width=1.5,stat="identity") +
ggplot2::coord_polar(theta="y") +
ggplot2::ggtitle("geom_bar") +
ggplot2::xlim(c(0,4)) +
ggplot2::theme_void()
p2 <- d %>%
ggplot2::ggplot(ggplot2::aes(x=2,y=VAL,fill=GRP)) +
ggplot2::geom_col(width=1.5) +
ggplot2::coord_polar(theta="y") +
ggplot2::ggtitle("geom_col") +
ggplot2::xlim(c(0,4)) +
ggplot2::theme_void()
p3 <- d %>%
dplyr::mutate(YMAX=cumsum(VAL),
YMIN=dplyr::lag(YMAX,1,default=0)) %>%
ggplot2::ggplot(ggplot2::aes(x=0,ymin=YMIN,ymax=YMAX,color=GRP)) +
ggplot2::geom_linerange(size=7) +
ggplot2::coord_polar(theta="y") +
ggplot2::ggtitle("geom_Linerange") +
ggplot2::theme_void()
gridExtra::grid.arrange(p1,p2,p3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.