2016-05-20 109 views
2

y軸應該能夠從0-535,000運行,並且線應該在它們的位置上成比例。我沒有足夠的詞彙來描述這個問題,所以這裏有兩張照片。閃亮的R ggplot:散點圖軸已經很奇怪

See what I mean?

A closer look

server.R片斷

carbon_emissions <- read.csv("/Users/mathewsayer/Documents/Work/Level 7/Shiny Flat Tax/Carbon/Carbon_Emissions/data/carbon_emissions0513.csv") 

output$carbonPlot <- renderPlot({ 
pCarbon <- ggplot(data=carbon_emissions[carbon_emissions$category%in%input$emission_choose,], 
aes(x=year, y=co2, group=category, colour=category))+ 
geom_line()+ 
geom_point() 
pCarbon + labs(title="UK Domestic, Industry and Transport CO2 Emissions") 
}) 

ui.R片斷

checkboxGroupInput(
    "emission_choose", 
    label = "Plot CO2 emissions from various sectors", 
    choices = c(
     "Industrial and Commericial Electricity" = "i_c_electric", 
     "Industrial and Commericial Gas" = "i_c_gas", 
     "Large Industrial Installations" = 
     "large_industry", 
     "Other Industrial and Commericial Fuels" = "i_c_other_fuel", 
     "Agriculture" = 
     "agriculture",)) 

plotOutput("carbonPlot") 

數據樣本

year,co2,category 
2005,"110,579.1",i_c_electric 
2006,"116,665.8",i_c_electric 
2007,"113,343.8",i_c_electric 
2008,"112,510.3",i_c_electric 
... 
2010,7.6,pc_emission 
2011,6.9,pc_emission 
2012,7.1,pc_emission 
2013,7.0,pc_emission 

預先感謝好人。

回答

3

看起來像你的co2變量是一個字符而不是數字。

只需在閱讀文件後執行以下操作。

carbon_emissions$co2 <- as.numeric(gsub(",", "", carbon_emissions$co2))