I have a data frame called toplot_noind
as shown below.
> toplot_noind
Chang.1 Chang.2 Chang.3 Chang.4 Chang.5 Chang.6 Chang.7 Chang.8
18 150.3 84.61 31.45 11.08 -0.19 -57.83 -88.63 -98.39
I would want to use this data frame to plot a bar graph using ggplot2.
I do not need the column names: Chang.1, Chang.2, etc., in the graph.
I want these 8 values 150.3, 84.61, ..., -98.39 to appear on the y-axis (18 is not part of the values, it is the name of the row).
Also since there are 8 values, I want 8 bars on the x-axis - each pointing to each of these values.
Therefore, I will want to name these bars as 1(for the 1st bar), 2(for the 2nd bar), 3, ..., 8 in that order, on the x-axis.
Also, I would want to label the y-axis as “Total Expected Profit” and the x-axis as “premium change”.
Shown below is what I have tried to do but it does not work. Actually I have tried reading on the ggplot2 but the material I read could not give me solid understanding but I need to use this bar graph in my assignment. I have very limited time to submit.
library(reshape)
library(ggplot2)
t<-ncol(toplot_noind)
a<-seq(1:t)
ggplot(toplot_noind, aes(x = a, y = toplot_noind, xlab="premium change", ylab="Total Expected Profit")) +
geom_bar(position = "dodge")
Many thanks in advance to all those who could be of help to me.
Isaac