Open tpemartin opened 2 years ago
dx=3 #input$dx t= 1 #input$t
ggplot()+ geom_col( mapping = aes( x=c(1,1,1), y=c(38,5,57), group=c("c","b","a"), fill=c("a","b","c") ) )+geom_text( mapping = aes( x=c(1+t,1+t), y=c(5,90), label=c("38%","57%") ), position = "stack", size=14 #input$size )+xlim(1-dx, 1+dx)+coord_flip()+theme_void()+ theme(legend.position = "none")
dx=4 #input$dx dt=0 #input$dt ggplot()+ geom_col( mapping=aes( x=c(1, 1 ,1), y=c(38,5 ,57), fill=c("韓總機","奧運4年","台灣價值"), group=c("韓總機","奧運4年","台灣價值"), ), width=1 )+ geom_text( mapping=aes( x=1+dt, y=19, label="韓總機" ), size=5 )+ geom_text( mapping=aes( x=1+dt, y=71, label="台灣價值" ), size=5 )+ geom_text( mapping=aes( x=2+dt, y=5, label="38%" ), size=5 )+ geom_text( mapping=aes( x=2+dt, y=95, label="57%" ), size=5 )+ geom_text( mapping=aes( x=2+dt, y=40, label="5%" ), size=5 )+ xlim(1-dx, 1+dx)+ # make sure cover 0.5-1.5 so the bar width can be accomodate coord_flip()+ theme_void()+ theme(legend.position = "none")
dw=7 #input$dw
dx=1.5#input$dx
size=20 #input$size
dy=0.09 #input$dy
py=0.06 #input$py
dy1=0.04 #input$dy1
px=0.15 #input$px
ggplot()+
geom_col(
mapping=aes(
x=c(1,1,1),
y=c(0.38,0.05,0.57),
fill=c("a","b","c")
),
width=1
)+
coord_flip()+
xlim(1-dw,1+dw)+
theme_void()+
theme(legend.position = "none")+
geom_text(
mapping = aes(
x=c(1+dx,1+dx),
y=c(0+dy1,1-dy),
label=c("38","57")
),
size=size
)+
geom_text(
mapping = aes(
x=c(1+dx-px,1+dx-px),
y=c(0+dy1+py,1-dy+py),
label=c("%","%")
),
size=size*0.5
)
https://tpemartin.github.io/economic-data-visualization-2021/categorical-data.html#section-3