newbie here:) I would appreciate any help/advise you could give me. I am trying to plot/scatterplot/boxplot/hist the data I have for some visual inspection, and lets say I got where I wanted to be, with some other commands...but then when I tried the same with ggplot I cannot get to the end of it.
This is part of my data "alc3"> with dummy variables for each beverage type
Author est se beer wine spirits
1 Andrikopoulos and Loizides(2000) -1.00 0.18 1 0 0
2 Andrikopoulos and Loizides(2000) -0.35 0.32 1 0 0
3 Andrikopoulos et al. 1997 -1.00 0.46 1 0 0
4 Andrikopoulos et al. 1997 -1.02 0.46 1 0 0
5 Adrian and Ferguson(1987) -0.84 0.17 1 0 0
6 Andrikopoulos et al. 1997 -0.48 0.13 1 0 0
7 Andrikopoulos et al. 1997 -0.08 0.07 1 0 0
8 Quek(1988) -0.28 0.03 1 0 0
9 Johnson et al.(1992) -0.14 0.05 1 0 0
10 Johnson et al.(1992) -0.26 0.06 1 0 0
11 Selvanathan and Selvanathan(2005) -0.43 0.11 1 0 0
12 Adrian and Ferguson(1987) -0.37 0.15 1 0 0
13 Selvanathan(1991) -0.26 0.17 1 0 0
14 Quek(1988) -0.16 0.22 1 0 0
15 Lau(1975) -0.43 0.39 1 0 0
16 Selvanathan and Selvanathan(2004) -0.16 0.03 1 0 0
I want to be able to crate boxplot or scatterplots, with ggplot for only one beverage(est), i.e. beer. If I use this code>
boxplot(est[beer=="1"] ~ Author[beer=="1"],
main="Boxplot of Bier elasticities",
xlab="Price elasticity", ylab=" ",
ylim=c(-5,3), las=1,
horizontal = TRUE)
Then I can select beer/wine/spirits respectively and get three different boxplots (or histograms - which is my goal, since I want to assess them separately) but with ggplot i can generate the code only for all beverages together.
ggplot(alc3, aes(x=est, y=Author) + geom_boxplot() +
ggtitle("Price elasticities of alcohol") +
xlab("Estimates") +
ylab(" "))
I tried to generate new variables
beer1 <- alc3$est[beer=="1"]
Author1 <- alc3$Author[beer=="1"]
But even when I replace them in aes(x=beer1, y=Author1)....i get this error message>
Error: Aesthetics must be either length 1 or the same as the data (406): x and y"
although they have the same length.
Is there any other way? Could anyone advise what should be changed.
Many thanks!! Anita