Increase the radius of the Circle in ggplot2 - r

I've had trouble increasing the radius of the circle on a map. I've tried the scale_size_continuous with maximum size up to 1000, but the circle size remained the same after all.
My code is in the following:
states <- map_data("state")
gg1 <- ggplot(data=states) +
geom_polygon(data=states, aes(x=long,y=lat,group=group),
fill = "orange", color = "white") +
coord_fixed(ratio = 1.3)+
geom_circle(data = origCity, aes(x0 = Long, y0 = Lat, r = Percent),
fill = "black", color = "black", alpha = 0.5, show.legend = FALSE) +
scale_size_continuous(range = c(20, 5))+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())+
theme(axis.ticks.x = element_blank(),
axis.title.x = element_blank(),
axis.text.x = element_blank())+
theme(axis.ticks.y = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank())
print(gg1)
Any suggestions are greatly appreciated!

Related

Combine 2 plots (ggplot) but use one legend and colour scheme

I have created 2 plots and combined them as seen below but i now wish to plot this with one legend and the same colour scheme for both plots, does anyone know what changes i need to make this?
code used to create plots
#plotting actual from 1998-2020
mapplot_temp = ggplot(map_preds20, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = GDP_pdiff), colour = "black")
mapplot1 = mapplot_temp + scale_fill_gradient(name = 'GDP per capita change %', low =
'red', high = 'yellow', na.value = 'grey') +
theme_bw() +
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(hjust = 0.5, size = 20, face = "bold"))
#plotting predicted from 2021-2040
mapplot_temp2 = ggplot(map_preds40, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = GDP_pdiff), colour = "black")
mapplot2 = mapplot_temp2 + scale_fill_gradient(name = 'GDP per capita change % ($)', low = 'red', high = 'yellow', na.value = 'grey') +
ggtitle('Predicted GDP per capita change') +
theme_bw() +
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(hjust = 0.5, size = 20, face = "bold"))
#combine plots with one legend and same colour scheme
mapplot1 + mapplot2
plot

Make the point in the middle of each grid in ggplot2?

Here is the data.
df <- data.frame(x = LETTERS[1:5], y = LETTERS[6:10], z = rnorm(5))
Below are the codes to generate a point plot.
ggplot(df, aes(x, y, fill = z, size = z)) +
geom_point(shape = 21, stroke = 1, colour = 'black')
I'm wondering how to make each point into the middle of each grid. Something like this.
I found it worked by adding a geom_tile function.
ggplot(df, aes(x, y)) +
geom_tile(fill = NA, colour = 'black') +
geom_point(aes(fill = z, size = z), shape = 21, stroke = 1, colour = 'black') +
theme(panel.background = element_blank(),
plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line.x = element_blank(),
axis.line.y = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
axis.title = element_text(size = 12),
axis.text.y = element_text(size = 10, colour = 'black'),
axis.text.x = element_text(size = 10, colour = 'black'),
strip.background = element_blank(),
strip.text = element_blank())

R ggplot viridis change the color gradient

Hello I am plotting scatter plot using R ggplot for coloring using virdis, I wanted split the color legend to get more contrast between ranges currently legend having 1000,2000,3000,4000 In between this split this to get more color currently my code looking as below
library(dplyr)
library(ggplot2)
library("viridis")
df <- tibble(gene = sample.int(5000),aceth = rnorm(5000),acvitd = rnorm(5000))
df$log_mean=log(df$gene)
p=ggplot(df, aes(aceth, acvitd))+
geom_point(aes(color =gene)) +
theme(legend.position = "top")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))
p=p+ theme(legend.position = "top") +
scale_color_viridis(option = "A",
name = "mean",
guide = guide_colourbar(direction = "horizontal",
barheight = unit(4, units = "mm"),
barwidth = unit(100, units = "mm"),
draw.ulim = F,
title.hjust = 0.5,
label.hjust = 0.5, title.position = "top"))
How I wanted my graph look like
can anyone suggest me
Perhaps you're looking for scale_colour_vridis_b to bin your colours?
df <- tibble(gene = sample.int(5000),aceth = rnorm(5000),acvitd = rnorm(5000))
df$log_mean=log(df$gene)
p=ggplot(df, aes(aceth, acvitd))+
geom_point(aes(color = - (aceth + acvitd))) +
theme(legend.position = "top")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))
p+ theme(legend.position = "top") +
scale_colour_viridis_b(option = "A", values = 0:10 /10, breaks = 0:5 - 2.5)

Modify the size of a pie chart with ggplot in R

I have run the following ggplot function :
g <- ggplot(results_table, aes(x = "", y = Pct*100, fill = Criteria),width = 0.5) +
geom_bar(stat = "identity", color = Palcolor, fill = Palcolor) +
coord_polar(theta = "y", start = 0, direction = -1) +
theme_minimal() +
theme(legend.position = "none", axis.title.x = element_blank(), axis.title.y = element_blank(),
panel.border = element_blank(), panel.grid = element_blank(), axis.text = element_blank(),
axis.ticks = element_blank(), legend.title = element_blank(),
plot.title = element_text(size = 14, hjust = 0.5, vjust = 0)) +
geom_text(aes(label = paste0(Criteria,"; ",sprintf("%0.1f", round(Pct*100, digits = 1)),"%")),
position = position_stack (vjust = 0.5, reverse = TRUE)) +
labs(title = gTitle)
}
and the pie is the following :
but it is too large. I would like to have a diameter smaller than the length of the second part of the title. How can I proceed ?

Changing the labels on ggplot legend

I'm using ggplot so I can get a gradient onto a map to show data over a large scale. There are points between 0 and 35,000 to be visualised. I have got this to work, but the legend is automatically showing labels for every 10,000.
Ideally I want the legend to show the maximum amount, so probably it would just show 0 at the bottom and 35,000 at the top. Is this doable?
My ggplot code is below if this helps.
ggplot() +
geom_map(data = datafile, aes(map_id = Health_Board, fill = datafile$"2007"), map = Scot) +
geom_polygon(data = Scot, aes(x = long, y = lat, group = group), colour = "gray", fill = NA) +
expand_limits(x = Scot$long, y = Scot$lat) +
scale_fill_gradient(low = ("lightyellow"), high = ("red"), limits = c(0,35000)) +
ggtitle("2007") +
coord_fixed(1.2) +
theme(axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(), axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_blank(), panel.background = element_blank(),
legend.title = element_text(face = "bold"),
plot.title = element_text(face = "bold", hjust = 0.5))
You can include the "breaks" argument. Like this:
scale_fill_gradient(low = ("lightyellow"), high = ("red"),
breaks=c(min(lat),max(lat)),
limits = c(0,35000)) +
If you want more, its possible to include the "labels" argument.
scale_fill_gradient(low = ("lightyellow"), high = ("red"),
breaks=c(min(lat),max(lat)),
labels=c("Minimum","Maximum"),
limits = c(0,35000)) +

Resources