plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.57k stars 626 forks source link

Alignment of ggtitle #781

Open soedr opened 8 years ago

soedr commented 8 years ago

First off, thank you for an incredible set of packages!

I'm facing an issue where the ggplot2 title aesthetics are not translated through ggplotyl(); more precisely, the horizontal title adjustment theme(plot.title = element_text(hjust = 0)) is ignored.

Code below:

library(ggthemes)
library(plotly)

set.seed(12345)
v <- runif(100, min=0, max=100)
df <- as.data.frame(v)
names(df) <- c("pressure")

t <- ggplot(df, aes(x = pressure)) +
  geom_histogram(bins = 20, alpha = 0.7, position = "identity") +
  scale_fill_fivethirtyeight(label = comma) +
  theme_tufte(base_size = 7, base_family = "Avenir") +
  labs(x =  "pressure", "# observations", title = "pressure plot") +
  theme(plot.title = element_text(hjust = 0)) +
  theme(axis.ticks = element_blank()) +
  scale_x_continuous()
(gg <- ggplotly(t))

Is there another way to define the location of text elements? Thanks!

ChrisMuir commented 7 years ago

I came here to mention this issue. Took a quick look through ggplotly.R and it looks like theme$plot.title$hjust is never accessed within the input ggplot object. I see the # TODO: hjust/vjust? comment within function make_label, is that related to this issue?

skanskan commented 3 years ago

Hello.

I've found the same problem. I'm trying to place the title within the plot are with

theme(plot.title = element_text(vjust = -15))

It works with ggplot but when feed it to ggplotly this options is just ignored.

geom_text(x, y, "text") doesn't work either.

I think I have to use %>% layout(title="My Title") But I can't figure out how to place it within the plot.