I am trying to plot scatter plot of pie charts using ggplot2 and ggforce. Following is my code
library(data.table)
library(ggplot2)
library(ggforce)
library(dplyr)
df <- fread("data_frame_pie_plot.csv", header = TRUE,
data.table = FALSE, stringsAsFactors = FALSE)
req_data <- apply(df, 1, function(x){
geom_arc_bar(aes(x0 = x0, y0 = y0, r0 = 0, r = 0.45,
amount = amount, fill = discrete_fill), stat = "pie")})
ggplot(df) + req_data + theme_no_axes()
plot_obtained
Link_to_data Data_frame.
Can I fill the colours manually (discrete(based on discrete_fill column)
and continous (based on conti_fill column))?
I have tried the following codes.
##================================================================================##
# Code 1
my_colors <- c("red","white","blue")
ggplot(df, fill = sample_mut_colour) + req_data +
theme_no_axes() + scale_color_manual(values=my_colors)
##================================================================================##
# Code 2
my_colors_1 <- c("red", "white")
my_colors_2 <- c("blue", "white")
req_data <- apply(df, 1, function(x){
geom_arc_bar(aes(x0 = x0, y0 = y0, r0 = 0, r = 0.45,
amount = amount,
fill = discrete_fill,
color = case_when(discrete_fill == 1 ~ my_colors_1,
discrete_fill == 2 ~ my_colors_2)), stat = "pie")})
ggplot(df) + req_data + theme_no_axes()
##================================================================================##
# Code 3
req_data <- apply(df, 1, function(x){
geom_arc_bar(aes(x0 = x0, y0 = y0, r0 = 0, r = 0.45,
amount = amount,
fill = case_when(discrete_fill == 1 ~ my_colors_1,
discrete_fill == 2 ~ my_colors_2)), stat = "pie")})
ggplot(df) + req_data + theme_no_axes()
##================================================================================##
# Code 4
req_data <- apply(df, 1, function(x){
geom_arc_bar(aes(x0 = x0, y0 = y0, r0 = 0, r = 0.45,
amount = amount,
fill = discrete_fill),
palette = case_when(discrete_fill == 1 ~ "red",
discrete_fill == 2 ~ "black",
TRUE ~ "white"), stat = "pie")})
ggplot(df) + req_data + theme_no_axes()
##=================================================================================##
But they do not seem to work. Any idea what is wrong in the code?