괄호 위에 "배"와 "애플"을 텍스트로 추가하고 싶습니다. 여러 제목, 동일한 크기 및 동일한 위치로 추가하는 방법을 찾을 수 없습니다.
df <- data.frame('fruit'=c("Apple", "Apple", "Apple", "Apple", "Pear", "Pear"),
'color'=c("Red", "Red", "Green","Green","Green","Green"), fruitcol=c(rep("AppleRed",2), rep("AppleGreen",2),rep("PearGreen",2)), 'percentage'= c(11,19,34,23,27, 16))
df$fruitcol <- factor(df$fruitcol, levels = c("AppleRed", "AppleGreen", "PearGreen"),labels = c( "Red", "Green", "Green_"))
the_plot<- ggplot(data=df, aes(x=fruit, y=percentage)) +
geom_bar(stat="identity") + facet_wrap(~fruitcol, labeller = label_parsed) + labs(title = "Pear", subtitle="Apple")+ theme(plot.subtitle=element_text(size=18, hjust=0.5, face="italic", color="black"))+
scale_x_discrete("",breaks=c(.5,2.5),labels=c("Low types","High types") ) +
theme(axis.ticks = element_blank(), axis.ticks.length = unit(.85, "cm"), strip.background = element_rect(
color="black", fill="#FC4E07", size=1.5, linetype="solid"))
library(pBrackets)
the_plot
grid.locator(unit="native")
top_y <- 40
grid.brackets(55, top_y, 360, top_y, lwd=2, col="black")
grid.brackets(370, top_y, 518, top_y, lwd=2, col="black")
나는 teunbrand의 중첩 패싯 옵션을 선호하지만 여기에 해킹이 있습니다.
매우 자주 플롯 패널 외부에 주석을 달 수 있습니다.
레이블에 대해 합리적인 테마 여백과 y- 값을 수동으로 선택해야합니다.
나는 또한 내가 생각 df
이 기본 기능이 될 것이라고 오랫동안 착각했다는 것을 알게되어 기쁩니다 . 나는 마침내 사람들이 데이터 프레임에 이것을 사용하지 않도록 설득하려는 내 탐구를 포기할 수 있습니다. 감사합니다 teunbrand
library(tidyverse)
library(ggtext)
library(grid)
library(pBrackets)
df <- data.frame('fruit'=c("Apple", "Apple", "Apple", "Apple", "Pear", "Pear"),
'color'=c("Red", "Red", "Green","Green","Green","Green"), fruitcol=c(rep("AppleRed",2), rep("AppleGreen",2),rep("PearGreen",2)), 'percentage'= c(11,19,34,23,27, 16))
df$fruitcol <- factor(df$fruitcol, levels = c("AppleRed", "AppleGreen", "PearGreen"), labels = c( "Red", "Green", "Green_"))
df$title_lab <- rep(c("Pear", "italic('Apple')",""), each = 2)
mypercent <-
df %>%
group_by(fruit, color) %>%
summarise(sum_perc = sum(percentage))
maxperc <- max(mypercent$sum_perc)
the_plot<-
ggplot(data = df, aes(x=fruit, y=percentage)) +
geom_col() +
geom_text(aes(x = 1, y = maxperc + 15, label = title_lab), parse = TRUE)+
facet_wrap(~ fruitcol, labeller = label_parsed) +
scale_x_discrete(NULL, breaks=c(.5,2.5), labels=c("Low types","High types") ) +
coord_cartesian(clip = "off", ylim = c(NA, maxperc)) +
theme(axis.ticks = element_blank(),
strip.background = element_rect(
color="black", fill="#FC4E07", size=1.5, linetype="solid"),
plot.margin = margin(t = .5, unit = "in"))
the_plot
grid.locator(unit="native")
top_y <- 40
grid.brackets(55, top_y, 360, top_y, lwd=2, col="black")
grid.brackets(370, top_y, 518, top_y, lwd=2, col="black")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다