I want to create a chart with the package packcircles as well as ggplot. and export it with the print device I use in this case "ragg".
I have two issues
When I export the chart to a png file , the chart gets squeezed into half of the plotting area. The exported chart must be a square and The title should fit into the whole plotting area.
The text inside the bubbles , I want to be able to resize it so it fits the size of the bubbles. And want to add another numeric text (column/variable:ptg) to each bubble with a different size.
I have tried this:
theme_bubble <- function( ) {
theme(
panel.background = element_rect(fill ="gray80"),
panel.grid.major.y = element_line(color = "gray80"),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill="gray80"),
legend.background = element_rect(fill="transparent"),
plot.title.position = "plot",
plot.title = element_textbox(size=35,color="white",vjust=1,
family = "merriweather",width = unit(1, "npc"),
margin= margin(r=-40,b=80),
lineheight = 1.3),
plot.subtitle = element_textbox_simple(size=20,color="grey80",
margin= margin(t=10,b=28,r=-40),
family = "montserrat",
width = unit(1, "npc")),
plot.caption.position = "plot",
plot.caption = element_textbox(size=12,color="grey85",margin= margin(t = 10, b=10,r=60),
lineheight = 1.2,
family = "montserrat",
width = unit(1, "npc")),
plot.margin = unit(c(1,2,0,1),"cm"),
)
}
######
df1 <- data.frame(birds = c("Eagle", "Owl", "Falcon", "Ostrich", "Blue Jay"),
values = c(46, 29, 55, 100, 17),
ptg = c(20,10,15,30,25))
df1$packing <- circleProgressiveLayout(df1$values, sizetype='area')
df1.gg <- circleLayoutVertices(df1$packing, npoints=50)
tp <- "Headline news august 23 2023, boldface"
c1 <- "Source: WWW "
p <- ggplot() +
geom_polygon(data = df1.gg, aes(x, y, group = id, fill=id), alpha = 0.6)+
labs(title = tp,
caption = c1) +
scale_fill_viridis_c()+
geom_text(data = df1, aes(x=packing$x, y=packing$y, label = birds), size=5, color="black") +
theme_bubble() +
coord_equal()
agg_png("prue.png", width = 10, height = 10, units = "in", res = 300)
p
dev.off()
I get this:
