I have the following R code which contains some dummy data. I am trying to create a bubble chart where the size of the bubble is dependent on the amount and is positioned based on the profitability (as a % of the amount) on the x-axis and the volatility (as a % of the amount) on the y-axis. Code is as follows:
rio_csv <- import("~/Desktop/R/Dummy Data.csv")
# Select columns to go into df
df <- data.frame("Volpc" = rio_csv[,6],"Profitpc"= rio_csv[,5],"Amount"= rio_csv[,4])
#Plot Bubble Chart
plot <- ggplot(df, aes(x = Profitpc, y = Volpc, size = Amount)) +
geom_point(alpha = 0.2) + scale_size(range = c(5,15)) + xlab("Profitability %") +
ylab("Volatility %")
plot
The profitability measure on the x-axis is a percentage and the volatility on the y-axis is a percentage. They both have the data type 'character'.
My first problem is when i run the code a bubble chart appears but the x-axis is not in numerical order, the y-axis is in numerical order.
I tried to use the code df$Profitpc <- as.numeric(df$Profitpc) but this causes all the values in the column to go NA with the warning 'NAs introduced by coercion'.
Is there a way of ordering the x-axis so it is in numerical order (increasing)?
My second problem is that the scaling of both axes are not suitably scaled. Ideally i would like a situation where both axes have appropriate scaling such as 0 to the max % value. Is there a way to do this also? I am sorry if this is obvious. I have attached a picture of the chart to illustrate the issues.