ggplot2中的X轴:因子

时间:2017-03-21 07:29:52

标签: r plot ggplot2

我试图在ggplot中绘制两条散点线。 x轴是从1到10的整数。最初我写了以下代码:

auto t = std::make_shared<boost::asio::deadline_timer>(ios);

这导致以下情节

enter image description here

此处x轴是连续的,打印值如2.5,7.5。为了使它成为因素,即1,2,3,4,...,10我尝试放library(ggplot2) Answer <- c(1:10) EM = c(0.458,0.517,0.4,0.394,0.15,0.15,0.0,0.2,0.14,0.33) F1 = c( 0.56,0.63,0.632,0.704,0.502,0.524,0.488,0.64,0.5,0.593) test_data <- data.frame(EM,F1,Answer) ggplot(test_data, aes(Answer)) + geom_line(aes(y = EM, colour = "EM")) + geom_line(aes(y = F1, colour = "F1")) ,但这导致空图。我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:4)

保持数据的连续性。如果您想更改比例,请执行以下操作:

ggplot(test_data, aes(Answer)) + 
  geom_line(aes(y = EM, colour = "EM")) + 
  geom_line(aes(y = F1, colour = "F1")) +
  scale_x_continuous(breaks = 1:10)

resulting plot