How to edit the variables name in a ggplot without having to change the table data?

Asked

Viewed 593 times

0

I plotted my chart but would like to change the name of my variables of the x and y axis (not the name of the axis) for better visualization of the information without having to change everything in the matrix sheet. Is it possible to make this change by script? For example, I would like to rename one of the variables y called Fran to #MB02 the variables of axis x 134321 by #R01. Could use == for example?

Below is an example of the base matrix used to create the required objects.

myc_t
Date    Time    Receiver    Transmitter ID  Transmitter.Serial  Sensor.Value Sensor.Unit    Station Name    Longitude   Latitude
2019-04-29  05:31:33    134321  4828    Fran    1305297         28.7       °C             PRN               102          121
2019-04-29  08:52:08    134325  4830    Beni    1305283         4.2         m             MVW               102          178
2019-04-29  08:53:13    134325  4831    Silvo   1305283         28.6       °C             MVW               150          178



plot(rec_loc$Longitude,rec_loc$Latitude,pch=1,cex=1,col="black",xlab="Longitude",ylab="Latitude")
as.factor(myc_t$Receiver)->myc_t$Receiver
as.factor(myc_t$Transmitter)->myc_t$Transmitter
levels(myc_t$Transmitter)->tlev
levels(myc_t$Receiver)->rlev
dput(myc_t)
ggplot(myc_t, aes(x=Receiver, y=Transmitter))+ geom_point() + xlab("ID dos receptores") + ylab("ID dos tags") +
scale_x_discrete(labels = rlev) + scale_y_discrete(labels = tlev)
  • Can you please, edit the question with the departure of dput(myc_t) or, if the base is too large, dput(head(myc_t, 20))?

1 answer

1

I imagine that’s what you’re looking for:

    ggplot(myc_t, aes(x=Receiver, y=Transmitter))+ geom_point() + xlab("ID dos receptores") + ylab("ID dos tags") +
scale_x_discrete(labels = c("#R01", "#R02")) + 
  scale_y_discrete(labels = c("#MB01", "#MB02", "#MB03"))+
  theme(axis.text.x = element_text(angle = 90))
  • Yes! Thank you very much! But how do I put the variables horizontally? Thank you!

  • Guys, I can’t put the X-axis variables horizontally even using las=1. Can anyone help???

  • See if this is what you need! I modified my answer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.