Reputation: 71
I'm trying to create a stacked bar chart using r. I know a bit of R, but mainly SPSS. The barcharts are really ugly in SPSS so I have been trying to use ggplot2 to make something more elegant.
Following other posts, I have tried to make my variables work. I converted the data to long form. Because this is original research I can't give too many specifics on the case. The first column is categorical data, and the second is numeric, because I imported it from SPSS but is actually categorical as well.
In longform there are 110 obs and 2 variables. My code here is:
Barchart <- ggplot(psydatacomp, aes(x=PsyType, y=Agreement, fill=row)) +
geom_bar(stat = "identity")
psydatacomp is the matrix I created in order to remove the NaN's.
The error message I receive is:
Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 110, 0
I have a basic backing in R, but it's not strong enough to be able to interpret what this error message is saying. Any help would be great.
Upvotes: 1
Views: 482
Reputation: 46
An alternative to R would be to run the analysis in SPSS and use Excel to visualize your results. It's much easier to run a simple SPSS analysis and drop the output into Excel than to import to R. A stacked bar chart takes no time to produce in Excel. I only mention this because it sounds like you are new to R but are more familiar with SPSS.
Upvotes: 0
Reputation: 137
It seems that one of your variables is interpreted as a function. For example "row" is a function (just search ?row in R). You should change here the column name from "row" to "Row". Here is a similar case: ggplot Error: Don't know how to automatically pick scale for object of type function
Upvotes: 1