2

I am trying to plot bars for String categories with Wisp. In other words, I have a string (key) and a count (value) in my repl and I want to have a bar chart of the count versus the key.

I don't know if something easy exists. I went as far as the following hack:

val plot = bar(topWords.map(_._2).toList)
val axisType: com.quantifind.charts.highcharts.AxisType.Type = "category"
val newPlot = plot.copy(xAxis = plot.xAxis.map {
  axisArray => axisArray.map { _.copy(axisType = Option(axisType),
                                      categories = Option(topWords.map(_._1))) }
})

but I don't know if it works because I don't find a way to visualize newPlot. Or maybe adding a method to the Wisp source implementing the above is the way to go?

Thanks for any help.

PS : I don't have the reputation to create the wisp tag, but I would have...

1 Answer 1

3

Update: in wisp 0.0.5 or later this will be supported directly:

column(List(("alpha", 1), ("omega", 5), ("zeta", 8)))

enter image description here

====

Thanks for trying out wisp (I am the author). I think a problem that you may have encountered is by naming your variable plot, you overrode access to the plot method defined by Highcharts, which allows you to plot any Highchart object. (now that I see it, naming your plot "plot" is an unfortunately natural thing to do!)

I'm filing this as a github issue, as category names are very common.

This works for me. I used column for vertical bars:

import com.quantifind.charts.Highcharts._
val topWords = Array(("alpha", 14), ("beta", 23), ("omega", 18))
val numberedColumns = column(topWords.map(_._2).toList)
val axisType: com.quantifind.charts.highcharts.AxisType.Type = "category"
val namedColumns = numberedColumns.copy(xAxis = numberedColumns.xAxis.map {
  axisArray => axisArray.map { _.copy(axisType = Option(axisType),
                                       categories = Option(topWords.map(_._1))) }
})
plot(namedColumns)

producing this visualization: enter image description here

(You could also consider creating one bar at a time, and use the legend to name them)

Sign up to request clarification or add additional context in comments.

6 Comments

Hi, thanks for your answer! Problem is that I don't have this behaviour. numberedColumns generate the first plot, but executing the namedColumns doesn't produce anything. Then again, I tried in the spark-shell (where I ultimately wants to use wisp). For the record, namedColumns returns com.quantifind.charts.highcharts.Highchart = Highchart(List(Series(Vector(Data(0,14,None,None), Data(1,23,None,None), Data(2,18,None,None)),None,None,None,Some(column),None,None,None,None,series)),... which looks wrong. I will test in a scala repl to see if your solution works there.
no luck with the sbt console, same behavior. PS I: tried on mac and linux for spark-shell, only on linux for sbt console. PS II: I pulled wisp and built a fat jar just now to do the test, but using scala 2.10.4, don't know if it matters.
Ah - I left it out of the response. You have to call plot(namedColumns). I tested this in the spark shell and it worked for me. Do you see two plots or only one?
ouch. Sorry for the blind copy paste... thanks a lot! it works.
Hey, I've modified wisp to more directly support named axis categories. Checkout the PR: github.com/quantifind/wisp/pull/31 Should go out with wisp 0.0.5
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.