Plot a row with the paramenters being the objects

As you can see in the code, I filtered a row of interest.

teste <- anos[, 1:73] %>% dplyr::filter(MUNICIPIO == "ABAETE (MG)", ANO == 2010)

with this code I get a row name and a value associated:
ALFAFA FENADA ALGODAO ARBOREO (EM CAROCO) ABACAXI ...
0 0 277

then I use the following to bring the row name to the vector

setDT(teste, keep.rownames = TRUE)

and then I transpose test so I can plot "teste"

teste <- t(teste)

BUUUT, the numbers in the second column generated are characters and, when I call

as.numeric(teste[, 2])

the numbers are changed. Like "0" become "1", "277" become "5"...

I am not sure if I was clear but I would appreciate any suggestion.

transposing with t makes a matrix, and all values have to be the same type therefore chars and numbers get turned to chars, but what you describe about them going to integers (and different ones than the string representations) sounds like they are factors.
maybe for lengthening data use pivot_longer() rather than t()

1 Like

Thanks, nirgrahamuk! That was the solution...

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.