2

I have created a simple line chart in plotly using ggplot2 and placed the plot in a box using box() function. However the plot overshoots the screen and I wish to resize the plot. Please help me with the same.

library(plotly)

datn <- read.table(header=TRUE, text='
supp dose length
OJ  0.5  13.23
OJ  1.0  22.70
OJ  2.0  26.06
VC  0.5   7.98
VC  1.0  16.77
VC  2.0  26.14
')

p <- ggplot(data=datn, aes(x=dose, y=length, group=supp, colour=supp)) +
geom_line() +
geom_point()

p <- ggplotly(p)

1 Answer 1

5

EDIT: sorry, I missed your comment that you were using box() to add a plot border (it wasn't in your example code). I'd recommend instead using ggplot2's panel border functionality:

p = p +
  theme(panel.border = element_rect(colour = "black", fill = NA, size = 3))

enter image description here

ORIGINAL: The code you've supplied isn't overshooting on my laptop:

enter image description hereBut if you need to, you can supply ggplotly() with explicit height and width arguments:

ggplotly(p, width = 500, height = 200)

enter image description here

The function has some other nice arguments for controlling the appearance of your plot.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much Rensa, this width and height attribute in ggplotly was what I was looking for. Great help pal, Thanks again.
No worries, @ASHMIN ☺️
If you could consider accepting the answer (the tick to the left of it), that'd be great :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.