-1

I am plotting various plots in the shiny app that I have developed, the raw dataset that I have, have all the data points in meters, for eg. one of my raw data set looks like this:

df <- data.frame(X = c(0.000000000000,4.99961330240E-005,9.99922660480E-005,0.000149988399072,0.00019998453209, 0.000249980665120,0.000299976798144,0.000349972931168,0.000399969064192,0.000449965197216,0.000499961330240,0.000549957463264,0.000599953596288,0.000649949729312,0.000699945862336,0.000749941995360,0.000799938128384,0.000849934261408,0.000899930394432,0.000949926527456,0.000999922660480,0.00104991879350,0.00109991492653,0.00114991105955),
Y = c(0.00120303964354,0.00119632557146,0.00119907223731,0.00120059816279,0.00119785149693,0.00119876705222,0.00119327372051,0.00118900112918,0.00118930631428,0.00119174779504,0.00119113742485,0.00119541001617,0.00119815668203,0.00119052705466,0.00119205298013,0.00118930631428,0.00119174779504,0.00119388409070,0.00118778038881,0.00122287667470,0.00122684408094,0.00122623371075,0.00122867519150,0.00122379222999))

My attempt to plot:

g <- ggplot(data =  df) + theme_bw() +
        geom_point(aes_string(x= df[,1], y= df[,2]), colour= "red", size = 0.1)
    ggplotly(g)

And the plot looks like this: enter image description here

What I want:

The data that I have in the datafile is in meters, but on the plot, I need Y-axis data to be shown in Micrometer and X-axis data to be shown in Millimeter. And the dataframe that I have illustrated above is just a small part of my actual dataframe. In the actual dataframe, data is very big.

Is there any way we can do this automatically without having the user to change the units manually?

In the end, I want 'Y' values to be multiplied by 10^6 and 'X' value to be multiplied by 10^3 in order to convert them into micrometers and millimeters respectively.

kolas0202
  • 163
  • 1
  • 7

1 Answers1

0

I got two possible answers to my question:

1st is:

g <- ggplot(data =  df) + theme_bw() +
     geom_point(aes_string(x= df[,1]*10^3, y= df[,2]*10^6), colour= "red", size = 0.1)
     ggplotly(g)

2nd is:

M <- data.frame(x= df[,1]* 10^3, y= df[,2]* 10^6)

g <- ggplot(data =  M) + theme_bw() +
     geom_point(aes_string(x= M[,1], y= M[,2]), colour= "red", size = 0.1)
     ggplotly(g)
kolas0202
  • 163
  • 1
  • 7