[R] length of 'dimnames'  not equal to array extent- For Correlation Plot
sarah.goslee at gmail.com
Sat Mar 17 17:58:24 CET 2018
That does clarify for me that you're missing a step: I didn't clearly
follow your description at first.
corrplot expects a correlation matrix, not your original data. You need to
use cor() first.
That's pretty clear in the documentation. See for instance the examples:
M <- cor(mtcars)
On Sat, Mar 17, 2018 at 12:00 PM Shivi Bhatia <shivipmp82 at gmail.com> wrote:
> Hi Sarah,
> Thank you for your help.
> I tried using CR1<-as.matrix(CR1) but gives error Error in corrplot(CR1,
> method = "circle") : The matrix is not in [-1, 1]!. I am using a corrplot
> Please find the reproducible example:
> structure(c(26L, 46L, 39L, 38L, 47L, 59L, 56L, 61L, 43L, 60L,
> 78L, 63L, 2L, 58L, 8L, 1L, 1L, 9L, 11L, 2L, 1037500L, 46747L,
> 346300L, 672000L, 729000L, 470800L, 423000L, 72184L, 368022L,
> 1037500L), .Dim = c(10L, 3L), .Dimnames = list(NULL, c("AGE",
> "OLD_CAR_PURCHASE_YRS", "Total.Spend.With.Maruti")))
> Please advice if this would help.
> Thank you. Shivi
> On Sat, Mar 17, 2018 at 8:45 PM, Sarah Goslee <sarah.goslee at gmail.com>
>> I'm assuming you are using the corrplot package.
>> If so, your data object does need to be a matrix, not a data frame.
>> Since it's already a data frame, your line of code:
>> doesn't need the as.data.frame function, but more importantly, you
>> didn't assign the result to anything: as.matrix() does not work in
>> CR1 <- as.matrix(CR1)
>> Now try.
>> If that doesn't work, then provide a reproducible example so we can
>> offer further advice.
>> On Sat, Mar 17, 2018 at 11:08 AM, Shivi Bhatia <shivipmp82 at gmail.com>
>> > Created a new data set with 3 numeric variable to find correlation
>> > CR1<- mar%>% as_data_frame%>% select(AGE, OLD_CAR_PURCHASE_YRS,
>> > Total.Spend.With.AA)
>> > had to convert it to a data frame, code:
>> > as.matrix(as.data.frame(CR1))
>> > Now i need to run a correlation plot for these 3 variables:
>> > corrplot(CR1, method = "circle")
>> > But i am getting this error:
>> > Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE),
>> nrow =
>> > nr, : length of 'dimnames'  not equal to array extent
>> > Researched and found Correlation
>> > <
>> > corrplot requires a matrix however the error is still the same.
>> > Regards, Shivi
>> > [[alternative HTML version deleted]]
>> > ______________________________________________
>> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > and provide commented, minimal, self-contained, reproducible code.
>> Sarah Goslee
[[alternative HTML version deleted]]
More information about the R-help