Create a Concentric Circle Legend for a Ggplot Bubble Chart

Aligning four 'nested' circles along their bottom edges in R

Convert area to radius, then use ggforce to draw circles:

library(ggforce)

#convert area to R
d$r <- sqrt(d$x / pi)
d$x0 <- max(d$r) / 2
d$y0 <- d$r

ggplot(d, aes(x0 = x0, y0 = y0, r = r, fill = circle)) +
geom_circle() +
theme_void()

Sample Image

Add € sign to data labels in bubble chart - ggplot?

Use package scales to change the geom_text label. The only change is

label = dollar(tooandja_kulu_aastas, prefix = "\u20ac")

the rest of the code is exactly the same as in the question.

library(ggplot2)
library(scales)

prx_col_palette <- function(){
c("#E69F00",
"#56B4E9",
"#009E73",
"#F0E442",
"#0072B2",
"#D55E00",
"#CC79A7")
}
prx_cols <- prx_col_palette()

ggplot(palgad_joonisele2,
aes(x = liik,
y = asutus,
colour = liik,
size = tooandja_kulu_aastas)) +
geom_point() +
geom_text(aes(label = dollar(tooandja_kulu_aastas, prefix = "\u20ac")),
colour = "white",
size = 3.5) +
scale_x_discrete(position = "top")+
scale_y_discrete(limits = rev)+
scale_size_continuous(range = c(14, 37)) +
scale_colour_manual(values = prx_cols)+
labs(x = NULL, y = NULL) +
theme(legend.position = "none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(size=11),
axis.text.y = element_text(size=11),
axis.ticks = element_blank())

Sample Image

Created on 2022-03-14 by the reprex package (v2.0.1)

R ggplot bubble chart localised bubbles display without in single chart

As an alternative to the @Wietze314 approach, "quick & dirty" single-chart built:

ggplot(data = sales_data, aes(x = month, y = dept_name)) +
geom_tile(data = expand.grid(sales_data$month, sales_data$dept_name),
aes(x = Var1, y = Var2), fill = NA, col = 'gray50', lty = 2) +
geom_point(aes(size = revenue, col = revenue),
shape = 16, position = position_jitter(seed = 0), show.legend = F) +
geom_text(aes(label = revenue), vjust = 1.6, position = position_jitter(seed = 0)) +
theme_bw() +
theme(
axis.title = element_blank(),
axis.ticks = element_blank(),
plot.background = element_blank(),
axis.line = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank()
)

Sample Image

How to name all circle in bubble chart in R

The reason for having only 6 labels is found here:

ex <- one.data [ one.data$dispensability < 0.15, ]; 
p1 <- p1 + geom_text( data = ex, aes(plot_X, plot_Y, label = description), colour = I(alpha("black", 0.85)), size = 3 );

The data frame ex is a subset with only six entries - all having dispensability values lower than 0.15. And this data frame is passed on to geom_text, which orders ggplot to render text labels.

If you want all labels, just don't use a subset but all data instead:

p1 <- p1 + geom_text(aes(plot_X, plot_Y, label = description), colour = I(alpha("black", 0.85)), size = 3 ); # shortcut for p1 <- p1 + geom_text(data = one.data, aes(plot_X, plot_Y, label = description), colour = I(alpha("black", 0.85)), size = 3 );
p1

Sample Image

or, if you want to declutter the labels, try

install.packages(ggrepel) # if needed
p1 <- p1 + ggrepel::geom_text_repel(aes(plot_X, plot_Y, label = description), colour = I(alpha("black", 0.85)), size = 3 )
p1;

Sample Image



Related Topics



Leave a reply



Submit