用R / plotly

时间:2018-08-11 11:17:02

标签: r plotly

我试图在我的标题之一中用R / Plotly书写摄氏度的符号。当我只使用下面的简单图时,它就起作用了:

# Working code
library(latex2exp)
set.seed(1)  
betas <- rnorm(1000)
hist(betas, main = TeX("Temperature (^0C)"))

但是,当我尝试通过代码运行代码时,出现以下错误:“'HashTableSetup'中未实现的类型'expression'”。

#Initialise the plot
p <- plot_ly()

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

#X axis name
x <- list(
  title = "x Axis",
  titlefont = f)


#Y Axis name
y <- list(
  title =  TeX("Temperature (^0C)"),
  titlefont = f)

#Add layout
p <- p %>%
  layout(xaxis = x, yaxis= y)

p

有什么想法吗?

3 个答案:

答案 0 :(得分:4)

尝试

<?php
    // Enabling error reporting
    error_reporting(-1);
    ini_set('display_errors', 'On');


    $title = isset($_GET['title']) ? $_GET['title'] : '';
    $body = isset($_GET['message']) ? $_GET['message'] : '';

    $message["title"] = $title;
    $message["body"] = $body;

     $fields = array(
                'to' => '/topics/global',
                'notification' => $message,
        );
    // Set POST variables
    $url = 'https://fcm.googleapis.com/fcm/send';

    $headers = array(
        'Authorization: key=' . FIREBASE_API_KEY,
        'Content-Type: application/json'
    );
    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    // Execute post
    $result='';
    if($title!=null){   
    $result = curl_exec($ch);

    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }
}    
    // Close connection
    curl_close($ch);
    ?>

答案 1 :(得分:2)

尝试title = expression("Temperature ("*~degree*C*")")title = "Temperature (°C)"

答案 2 :(得分:0)

我刚刚找到了一个有问题的解决方案:在google上查找特殊字符并将其直接复制并粘贴到R代码中。

# fixed parameter fof exact matching
res <- dfm_lookup(x, dic, valuetype = "fixed")
row.names(res)<- Reviews
res

我仍然对一种不太hacky的解决方案感兴趣,该解决方案允许将LaTeX插入Plotly。