Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly for R: Remove the k that apears on the y axis when the dataset contains numbers larger than 1000

Tags:

r

plotly

Hi a 'simple' question with plotly, I want to remove the k that seems to automatically appears on the y axis when the dataset contains numbers larger than 10000. I have tried uploading the data to plotly online and it puts the 'k' in as well.

for example using a subset of the data.

date <- c(1/07/1987,2/07/1987,3/07/1987,4/07/1987,
5/07/1987,6/07/1987,7/07/1987,8/07/1987,9/07/1987,
10/07/1987,11/07/1987,
12/07/1987,13/07/1987,14/07/1987,15/07/1987,
16/07/1987,17/07/1987,18/07/1987,19/07/1987,
20/07/1987,21/07/1987,22/07/1987,23/07/1987,
24/07/1987,25/07/1987,26/07/1987,27/07/1987,
28/07/1987,29/07/1987,30/07/1987,31/07/1987,
1/08/1987,2/08/1987,3/08/1987)


inflow <- c(6763.37,
6117.23,5487.1,4964.52,
4514.75,4074.88,3708.87,
3433.5,3199.78,3039.32,3063.06,
2938.13,2701.71,2577.23,3333.21,
5549.01,9194.34,10773.31,12919.33,
19590.91,17501.189,15660.45,14296.71,
12260.04,10202.66,8973.64,7865.35,
7044.35,13550.44,9923.3,11974.07,
11349.38,10869.92,10350.58)
inflow_guaged <- cbind(date, inflow)

inflow_guaged$Data <- "2016"

colnames(inflow_guaged) <- c("date","inflow","Data")


m <- list(
  l = 150,
  r = 40,
  b = 150,
  t = 50,
  pad = 0
)

f <- list(
  family = "Courier New, monospace",
  size = 18,
  color = "#7f7f7f"
)

x <- list(
  title = "Date",
  titlefont = f 
)

y <- list(
  title = "Inflow (ML/d)",
  titlefont = f
  )


p <- plot_ly(data = inflows_type, x = date, y = inflow, color = Data, colors = "Set1") %>%
  layout(xaxis = x, yaxis = y, margin = m ) 
like image 982
Tim Craig Avatar asked Sep 06 '25 03:09

Tim Craig


2 Answers

bei axis layout just do tickformat = "digit" or tickformat = "000"

like image 167
Ina Airapetsyan Avatar answered Sep 07 '25 20:09

Ina Airapetsyan


add this:

%>% layout(xaxis = list(tickformat = "digits"))

to your plot_ly object.

So in your case it should be something like:

x <- list(
  title = "Date",
  titlefont = f,
  tickformat = "digits"
)
like image 38
rdatasculptor Avatar answered Sep 07 '25 19:09

rdatasculptor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!