I am a beginner in r studio but i want to create a diagram for a term paper. I work with data from the European Social Survey(ESS) Round 9, which is freely available. http://nesstar.ess.nsd.uib.no/webview/index.jsp?v=2&submode=abstract&study=http%3A%2F%2F129.177.90.83%3A80%2Fobj%2FfStudy%2FESS8e02.2&mode=documentation&top=yes
data <- read.dta("ESS8.dta")
data_de <- data[(data$cntry=="DE"),]
I want to create a bar chart that shows the political activity of people (y axis) broken down on the levels of a scale from Political orientation (0=Left, 10 = Right).
For the political activity i want to use multiple items. This are the items I want to use:
data_de$pbldmn
data_de$badge
data_de$bctprd
data_de$contplt
data_de$pstplonl
data_de$sgnptit
data_de$wrkprty
data_de$wrkorg
all items are factor variables. The values look like this:
table(data_de$sgnptit) Yes No Refusal Don't know No answer 336 2516 0 0 0
They should be stacked on each other in the bar chart, but only with the answers "Yes". I know that you can use group = for this but the problem is that I don't have one variable with several groups. I only have multiple different variables.
I tried this code but it didn't worked
PolAkt <- rep(c(data_de$pbldmn, data_de$sgnptit, etc....)
ggplot(data = data_de, aes(x=data_de$lrscale, y=stat(count), group=factor(PolAkt)))
+geom_bar()
Error: Aesthetics must be either length 1 or the same as the data (2852): group
is there a another way to define these items as levels of a new variable?
I did a quick sketch how I would like the chart to look like, so you can maybe understand better what I want to do...
the political activity should be displayed proportional to the frequencies of the values of the x axis.
For example: The bar at lrscale 0 should show, how many % of the people who classified themselves on 0 on the scale from left(0) to right(10) are politically active and in which way.
would be very happy about any help!
EDIT
tried this:
data_PolAkt <- data.frame(PolAkt=c(data_de$lrscale, data_de$pbldmn, data_de$badge, data_de$bctprd, data_de$contplt, data_de$pstplonl, data_de$sgnptit, data_de$wrkprty, data_de$wrkorg))
ggplot(data_de, aes(x = data_de$lrscale, fill = PolAkt) ) +
geom_bar( aes(y = ..count..*100/sum(..count..) ) ) +
xlab("EinordnungLinksRechts") +
ylab("PolitischeAktivität") +
scale_fill_manual("Condition", values = alpha( c("firebrick", "dodgerblue4"), 1) )
and got this error: Error: Aesthetics must be either length 1 or the same as the data (2852): fill