ggplot在情节缺失的传奇中

时间:2016-09-19 19:38:13

标签: r ggplot2 plotly

我无法让一个传奇故事显示出来,特别是using System.ComponentModel; using System.Runtime.CompilerServices; namespace DemoWPFApp1.ViewModels { public class BaseViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged([CallerMemberName] string propName = null) { var e = PropertyChanged; if (e != null && propName != null) { e.Invoke(this, new PropertyChangedEventArgs(propName)); } } } }

我正在使用 class Bootstrap { protected $controller = 'home'; protected $method = 'index'; protected $params = []; function __construct($url) { $urlArray = $this->parseurl($url); if(file_exists('../app/http/controllers/' . $urlArray[0] . '.php')) { $this->controller = $urlArray[0]; unset($urlArray[0]); } require_once '../app/http/controllers/' . $this->controller . '.php'; $this->controller = new Controllers\$this->controller; var_dump($this->controller); } public function parseurl($url) { return $url = explode('/', filter_var(rtrim($url, '/'), FILTER_SANITIZE_URL)); } } ggplot + geom_line

为了演示我的问题,我将构建一个简单的数据框:

plotly 3.6.0

这会创建一个带有图例的ggplot图形。但是,当我尝试使用plotly创建交互式版本时,图例不再存在。

ggplot2 2.1.0

我尝试了以下方法来解决问题:

x = 1:5
y1 = 1:5
y2 = y1 * 2
d = data.frame(x, y1, y2)

g = ggplot(data = d, aes(x=x)) +
geom_line(aes(y = y1, col = 'y1')) + 
geom_line(aes(y = y2, col = 'y2')) + 
scale_color_manual(values = c('red', 'blue'), labels = c('y1 lab', 'y2 lab'), name = '')
g

1 个答案:

答案 0 :(得分:2)

library(reshape2)

d<-melt(d,id="x")
g <- ggplot(data = d, aes(x=x, y=value, color=variable)) +
  geom_line() +scale_color_manual(values = c('red', 'blue'), 
                                  labels = c('y1 lab', 'y2 lab'), name = '')
ggplotly(g)

enter image description here

相关问题